Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Side by Side Diff: chrome/browser/extensions/process_map.h

Issue 8769022: Add site_instance_id to ProcessMap::Item. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_EXTENSIONS_PROCESS_MAP_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_
6 #define CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_ 6 #define CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 13
14 namespace extensions { 14 namespace extensions {
15 15
16 // Contains information about which extensions are assigned to which processes. 16 // Contains information about which extensions are assigned to which processes.
17 // 17 //
18 // The relationship between extensions and processes is complex: 18 // The relationship between extensions and processes is complex:
19 //
19 // - Extensions can be either "split" mode or "spanning" mode. 20 // - Extensions can be either "split" mode or "spanning" mode.
20 // - In spanning mode, extensions share a single process between all incognito 21 // - In spanning mode, extensions share a single process between all incognito
21 // and normal windows. This was the original mode for extensions. 22 // and normal windows. This was the original mode for extensions.
22 // - In split mode, extensions have separate processes in incognito windows. 23 // - In split mode, extensions have separate processes in incognito windows.
23 // - There are also hosted apps, which are a kind of extensions, and those 24 // - There are also hosted apps, which are a kind of extensions, and those
24 // usually have a process model similar to normal web sites: multiple 25 // usually have a process model similar to normal web sites: multiple
25 // processes per-profile. 26 // processes per-profile.
27 // - A single hosted app can have more than one SiteInstance in the same process
28 // if we're over the process limit and force them to share a process.
26 // 29 //
27 // In general, we seem to play with the process model of extensions a lot, so 30 // In general, we seem to play with the process model of extensions a lot, so
28 // it is safest to assume it is many-to-many in most places in the codebase. 31 // it is safest to assume it is many-to-many in most places in the codebase.
29 // 32 //
30 // Note that because of content scripts, frames, and other edge cases in 33 // Note that because of content scripts, frames, and other edge cases in
31 // Chrome's process isolation, extension code can still end up running outside 34 // Chrome's process isolation, extension code can still end up running outside
32 // an assigned process. 35 // an assigned process.
33 // 36 //
34 // But we only allow high-privilege operations to be performed by an extension 37 // But we only allow high-privilege operations to be performed by an extension
35 // when it is running in an assigned process. 38 // when it is running in an assigned process.
36 // 39 //
37 // =========================================================================== 40 // ===========================================================================
38 // WARNINGS - PLEASE UNDERSTAND THESE BEFORE CALLING OR MODIFYING THIS CLASS 41 // WARNINGS - PLEASE UNDERSTAND THESE BEFORE CALLING OR MODIFYING THIS CLASS
39 // =========================================================================== 42 // ===========================================================================
40 // 43 //
41 // 1. This class contains the processes for hosted apps as well as extensions 44 // 1. This class contains the processes for hosted apps as well as extensions
42 // and packaged apps. Just because a process is present here *does not* mean 45 // and packaged apps. Just because a process is present here *does not* mean
43 // it is an "extension process" (e.g., for UI purposes). It may contain only 46 // it is an "extension process" (e.g., for UI purposes). It may contain only
44 // hosted apps. See crbug.com/102533. 47 // hosted apps. See crbug.com/102533.
45 // 48 //
46 // 2. An extension can show be in multiple processes. That is why there is no 49 // 2. An extension can show up in multiple processes. That is why there is no
47 // GetExtensionProcess() method here. There are two cases: a) The extension 50 // GetExtensionProcess() method here. There are two cases: a) The extension
48 // is actually a hosted app, in which case this is normal, or b) there is an 51 // is actually a hosted app, in which case this is normal, or b) there is an
49 // incognito window open and the extension is "split mode". It is *not safe* 52 // incognito window open and the extension is "split mode". It is *not safe*
50 // to assume that there is one process per extension. If you only care about 53 // to assume that there is one process per extension. If you only care about
51 // extensions (not hosted apps), and you are on the UI thread, then use 54 // extensions (not hosted apps), and you are on the UI thread, and you don't
55 // care about incognito version of this extension (or vice versa if you're in
56 // an incognito profile) then use
52 // ExtensionProcessManager::GetSiteInstanceForURL()->[Has|Get]Process(). 57 // ExtensionProcessManager::GetSiteInstanceForURL()->[Has|Get]Process().
53 // 58 //
54 // 3. The process ids contained in this class are *not limited* to the Profile 59 // 3. The process ids contained in this class are *not limited* to the Profile
55 // you got this map from. They can also be associated with that profile's 60 // you got this map from. They can also be associated with that profile's
56 // incognito/normal twin. If you care about this, use 61 // incognito/normal twin. If you care about this, use
57 // RenderProcessHost::FromID() and check the profile of the resulting object. 62 // RenderProcessHost::FromID() and check the profile of the resulting object.
58 // 63 //
59 // TODO(aa): The above warnings suggest this class could use improvement :). 64 // TODO(aa): The above warnings suggest this class could use improvement :).
60 class ProcessMap { 65 class ProcessMap {
61 public: 66 public:
62 ProcessMap(); 67 ProcessMap();
63 ~ProcessMap(); 68 ~ProcessMap();
64 69
65 size_t size() const { return items_.size(); } 70 size_t size() const { return items_.size(); }
66 71
67 bool Insert(const std::string& extension_id, int process_id); 72 bool Insert(const std::string& extension_id, int process_id,
68 bool Remove(const std::string& extension_id, int process_id); 73 int site_instance_id);
69 int Remove(int process_id); 74
75 bool Remove(const std::string& extension_id, int process_id,
76 int site_instance_id);
77 int RemoveAllFromProcess(int process_id);
78
70 bool Contains(const std::string& extension_id, int process_id) const; 79 bool Contains(const std::string& extension_id, int process_id) const;
71 bool Contains(int process_id) const; 80 bool Contains(int process_id) const;
72 81
73 std::set<std::string> GetExtensionsInProcess(int process_id) const; 82 std::set<std::string> GetExtensionsInProcess(int process_id) const;
74 83
75 private: 84 private:
76 struct Item { 85 struct Item;
77 Item();
78 Item(const Item& other);
79 Item(const std::string& extension_id, int process_id);
80 ~Item();
81
82 // Required for set membership.
83 bool operator<(const Item& other) const;
84
85 std::string extension_id;
86 int process_id;
87 };
88 86
89 typedef std::set<Item> ItemSet; 87 typedef std::set<Item> ItemSet;
90 std::set<Item> items_; 88 ItemSet items_;
91 89
92 DISALLOW_COPY_AND_ASSIGN(ProcessMap); 90 DISALLOW_COPY_AND_ASSIGN(ProcessMap);
93 }; 91 };
94 92
95 } // extensions 93 } // extensions
96 94
97 #endif // CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_ 95 #endif // CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/process_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698