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 EXTENSIONS_BROWSER_PROCESS_MAP_H_ | 5 #ifndef EXTENSIONS_BROWSER_PROCESS_MAP_H_ |
6 #define EXTENSIONS_BROWSER_PROCESS_MAP_H_ | 6 #define EXTENSIONS_BROWSER_PROCESS_MAP_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "extensions/common/features/feature.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 class BrowserContext; | 16 class BrowserContext; |
16 } | 17 } |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
| 20 class Extension; |
19 | 21 |
20 // Contains information about which extensions are assigned to which processes. | 22 // Contains information about which extensions are assigned to which processes. |
21 // | 23 // |
22 // The relationship between extensions and processes is complex: | 24 // The relationship between extensions and processes is complex: |
23 // | 25 // |
24 // - Extensions can be either "split" mode or "spanning" mode. | 26 // - Extensions can be either "split" mode or "spanning" mode. |
25 // - In spanning mode, extensions share a single process between all incognito | 27 // - In spanning mode, extensions share a single process between all incognito |
26 // and normal windows. This was the original mode for extensions. | 28 // and normal windows. This was the original mode for extensions. |
27 // - In split mode, extensions have separate processes in incognito windows. | 29 // - In split mode, extensions have separate processes in incognito windows. |
28 // - There are also hosted apps, which are a kind of extensions, and those | 30 // - There are also hosted apps, which are a kind of extensions, and those |
(...skipping 30 matching lines...) Expand all Loading... |
59 // care about incognito version of this extension (or vice versa if you're in | 61 // care about incognito version of this extension (or vice versa if you're in |
60 // an incognito profile) then use | 62 // an incognito profile) then use |
61 // extensions::ProcessManager::GetSiteInstanceForURL()->[Has|Get]Process(). | 63 // extensions::ProcessManager::GetSiteInstanceForURL()->[Has|Get]Process(). |
62 // | 64 // |
63 // 3. The process ids contained in this class are *not limited* to the Profile | 65 // 3. The process ids contained in this class are *not limited* to the Profile |
64 // you got this map from. They can also be associated with that profile's | 66 // you got this map from. They can also be associated with that profile's |
65 // incognito/normal twin. If you care about this, use | 67 // incognito/normal twin. If you care about this, use |
66 // RenderProcessHost::FromID() and check the profile of the resulting object. | 68 // RenderProcessHost::FromID() and check the profile of the resulting object. |
67 // | 69 // |
68 // TODO(aa): The above warnings suggest this class could use improvement :). | 70 // TODO(aa): The above warnings suggest this class could use improvement :). |
| 71 // |
| 72 // TODO(kalman): This class is not threadsafe, but is used on both the UI and |
| 73 // IO threads. Somebody should fix that, either make it |
| 74 // threadsafe or enforce single thread. Investigation required. |
69 class ProcessMap : public KeyedService { | 75 class ProcessMap : public KeyedService { |
70 public: | 76 public: |
71 ProcessMap(); | 77 ProcessMap(); |
72 virtual ~ProcessMap(); | 78 virtual ~ProcessMap(); |
73 | 79 |
74 // Returns the instance for |browser_context|. An instance is shared between | 80 // Returns the instance for |browser_context|. An instance is shared between |
75 // an incognito and a regular context. | 81 // an incognito and a regular context. |
76 static ProcessMap* Get(content::BrowserContext* browser_context); | 82 static ProcessMap* Get(content::BrowserContext* browser_context); |
77 | 83 |
78 size_t size() const { return items_.size(); } | 84 size_t size() const { return items_.size(); } |
79 | 85 |
80 bool Insert(const std::string& extension_id, int process_id, | 86 bool Insert(const std::string& extension_id, int process_id, |
81 int site_instance_id); | 87 int site_instance_id); |
82 | 88 |
83 bool Remove(const std::string& extension_id, int process_id, | 89 bool Remove(const std::string& extension_id, int process_id, |
84 int site_instance_id); | 90 int site_instance_id); |
85 int RemoveAllFromProcess(int process_id); | 91 int RemoveAllFromProcess(int process_id); |
86 | 92 |
87 bool Contains(const std::string& extension_id, int process_id) const; | 93 bool Contains(const std::string& extension_id, int process_id) const; |
88 bool Contains(int process_id) const; | 94 bool Contains(int process_id) const; |
89 | 95 |
90 std::set<std::string> GetExtensionsInProcess(int process_id) const; | 96 std::set<std::string> GetExtensionsInProcess(int process_id) const; |
91 | 97 |
| 98 // Guesses the most permissive context type for the process with ID |
| 99 // |process_id|. Context types are renderer (JavaScript) concepts but the |
| 100 // browser can do a decent job in guessing what the process hosts. |
| 101 // |
| 102 // - For hosted app processes, this will be blessed_web_page. |
| 103 // - For other extension processes, this will be blessed_extension. |
| 104 // - For WebUI processes, this will be a webui. |
| 105 // - For anything else we have the choice of unblessed_extension or |
| 106 // content_script. Since content scripts are more common, guess that. |
| 107 // We *could* in theory track which web processes have extension frames |
| 108 // in them, and those would be unblessed_extension, but we don't at the |
| 109 // moment, and once OOP iframes exist then there won't even be such a |
| 110 // thing as an unblessed_extension context. |
| 111 // |
| 112 // |extension| isn't used to upgrade the process trust level, but rather used |
| 113 // as a tiebreaker if a process is found to contain multiple extensions. |
| 114 Feature::Context GuessContextType(const Extension* extension, |
| 115 int process_id) const; |
| 116 |
92 private: | 117 private: |
93 struct Item; | 118 struct Item; |
94 | 119 |
95 typedef std::set<Item> ItemSet; | 120 typedef std::set<Item> ItemSet; |
96 ItemSet items_; | 121 ItemSet items_; |
97 | 122 |
98 DISALLOW_COPY_AND_ASSIGN(ProcessMap); | 123 DISALLOW_COPY_AND_ASSIGN(ProcessMap); |
99 }; | 124 }; |
100 | 125 |
101 } // namespace extensions | 126 } // namespace extensions |
102 | 127 |
103 #endif // EXTENSIONS_BROWSER_PROCESS_MAP_H_ | 128 #endif // EXTENSIONS_BROWSER_PROCESS_MAP_H_ |
OLD | NEW |