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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_PROCESS_MAP_H_
6 #define EXTENSIONS_BROWSER_PROCESS_MAP_H_
11 #include "base/basictypes.h"
12 #include "components/keyed_service/core/keyed_service.h"
18 namespace extensions
{
20 // Contains information about which extensions are assigned to which processes.
22 // The relationship between extensions and processes is complex:
24 // - Extensions can be either "split" mode or "spanning" mode.
25 // - In spanning mode, extensions share a single process between all incognito
26 // and normal windows. This was the original mode for extensions.
27 // - In split mode, extensions have separate processes in incognito windows.
28 // - There are also hosted apps, which are a kind of extensions, and those
29 // usually have a process model similar to normal web sites: multiple
30 // processes per-profile.
31 // - A single hosted app can have more than one SiteInstance in the same process
32 // if we're over the process limit and force them to share a process.
34 // In general, we seem to play with the process model of extensions a lot, so
35 // it is safest to assume it is many-to-many in most places in the codebase.
37 // Note that because of content scripts, frames, and other edge cases in
38 // Chrome's process isolation, extension code can still end up running outside
39 // an assigned process.
41 // But we only allow high-privilege operations to be performed by an extension
42 // when it is running in an assigned process.
44 // ===========================================================================
45 // WARNINGS - PLEASE UNDERSTAND THESE BEFORE CALLING OR MODIFYING THIS CLASS
46 // ===========================================================================
48 // 1. This class contains the processes for hosted apps as well as extensions
49 // and packaged apps. Just because a process is present here *does not* mean
50 // it is an "extension process" (e.g., for UI purposes). It may contain only
51 // hosted apps. See crbug.com/102533.
53 // 2. An extension can show up in multiple processes. That is why there is no
54 // GetExtensionProcess() method here. There are two cases: a) The extension
55 // is actually a hosted app, in which case this is normal, or b) there is an
56 // incognito window open and the extension is "split mode". It is *not safe*
57 // to assume that there is one process per extension. If you only care about
58 // extensions (not hosted apps), and you are on the UI thread, and you don't
59 // care about incognito version of this extension (or vice versa if you're in
60 // an incognito profile) then use
61 // extensions::ProcessManager::GetSiteInstanceForURL()->[Has|Get]Process().
63 // 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
65 // incognito/normal twin. If you care about this, use
66 // RenderProcessHost::FromID() and check the profile of the resulting object.
68 // TODO(aa): The above warnings suggest this class could use improvement :).
69 class ProcessMap
: public KeyedService
{
72 virtual ~ProcessMap();
74 // Returns the instance for |browser_context|. An instance is shared between
75 // an incognito and a regular context.
76 static ProcessMap
* Get(content::BrowserContext
* browser_context
);
78 size_t size() const { return items_
.size(); }
80 bool Insert(const std::string
& extension_id
, int process_id
,
81 int site_instance_id
);
83 bool Remove(const std::string
& extension_id
, int process_id
,
84 int site_instance_id
);
85 int RemoveAllFromProcess(int process_id
);
87 bool Contains(const std::string
& extension_id
, int process_id
) const;
88 bool Contains(int process_id
) const;
90 std::set
<std::string
> GetExtensionsInProcess(int process_id
) const;
95 typedef std::set
<Item
> ItemSet
;
98 DISALLOW_COPY_AND_ASSIGN(ProcessMap
);
101 } // namespace extensions
103 #endif // EXTENSIONS_BROWSER_PROCESS_MAP_H_