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