blob: 1d5eadbbd3dd94326905d1cb04bcadaf5f3ef3ca [file] [log] [blame]
[email protected]672c8c12013-03-07 12:30:061// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]a7b8e43d2013-03-18 18:52:435#ifndef CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_
6#define CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_
[email protected]672c8c12013-03-07 12:30:067
8#include <set>
9
avib896c712015-12-26 02:10:4310#include "base/macros.h"
[email protected]672c8c12013-03-07 12:30:0611#include "base/memory/ref_counted.h"
12
13namespace content {
14class ResourceContext;
15}
16
17namespace net {
18class URLRequest;
19}
20
21// IO thread data held for Instant. This reflects the data held in
22// InstantService for use on the IO thread. Owned by ResourceContext
23// as user data.
24class InstantIOContext : public base::RefCountedThreadSafe<InstantIOContext> {
25 public:
26 InstantIOContext();
27
28 // Key name for context UserData. UserData is created by InstantService
29 // but accessed by InstantIOContext.
30 static const char kInstantIOContextKeyName[];
31
32 // Installs the |instant_io_context| into the UserData of the
33 // |resource_context|.
34 static void SetUserDataOnIO(
35 content::ResourceContext* resource_context,
36 scoped_refptr<InstantIOContext> instant_io_context);
37
38 // Add and remove RenderProcessHost IDs that are associated with Instant
39 // processes. Used to keep process IDs in sync with InstantService.
40 static void AddInstantProcessOnIO(
41 scoped_refptr<InstantIOContext> instant_io_context,
42 int process_id);
43 static void RemoveInstantProcessOnIO(
44 scoped_refptr<InstantIOContext> instant_io_context,
45 int process_id);
46 static void ClearInstantProcessesOnIO(
47 scoped_refptr<InstantIOContext> instant_io_context);
48
49 // Determine if this chrome-search: request is coming from an Instant render
50 // process.
51 static bool ShouldServiceRequest(const net::URLRequest* request);
52
53 protected:
54 virtual ~InstantIOContext();
55
56 private:
57 friend class base::RefCountedThreadSafe<InstantIOContext>;
58
59 // Check that |process_id| is in the known set of Instant processes, ie.
60 // |process_ids_|.
61 bool IsInstantProcess(int process_id) const;
62
63 // The process IDs associated with Instant processes. Mirror of the process
64 // IDs in InstantService. Duplicated here for synchronous access on the IO
65 // thread.
66 std::set<int> process_ids_;
67
[email protected]672c8c12013-03-07 12:30:0668 DISALLOW_COPY_AND_ASSIGN(InstantIOContext);
69};
70
[email protected]a7b8e43d2013-03-18 18:52:4371#endif // CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_