Make default apps cache multiprofile friendly
[chromium-blink-merge.git] / chrome / browser / extensions / process_map.h
blob73439ad6460ffeb32aeeb56c0e50e5d2b6f01186
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_
6 #define CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_
8 #include <set>
9 #include <string>
11 #include "base/basictypes.h"
13 namespace extensions {
15 // Contains information about which extensions are assigned to which processes.
17 // The relationship between extensions and processes is complex:
19 // - Extensions can be either "split" mode or "spanning" mode.
20 // - In spanning mode, extensions share a single process between all incognito
21 // and normal windows. This was the original mode for extensions.
22 // - 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 // usually have a process model similar to normal web sites: multiple
25 // processes per-profile.
26 // - A single hosted app can have more than one SiteInstance in the same process
27 // if we're over the process limit and force them to share a process.
29 // In general, we seem to play with the process model of extensions a lot, so
30 // it is safest to assume it is many-to-many in most places in the codebase.
32 // Note that because of content scripts, frames, and other edge cases in
33 // Chrome's process isolation, extension code can still end up running outside
34 // an assigned process.
36 // But we only allow high-privilege operations to be performed by an extension
37 // when it is running in an assigned process.
39 // ===========================================================================
40 // WARNINGS - PLEASE UNDERSTAND THESE BEFORE CALLING OR MODIFYING THIS CLASS
41 // ===========================================================================
43 // 1. This class contains the processes for hosted apps as well as extensions
44 // and packaged apps. Just because a process is present here *does not* mean
45 // it is an "extension process" (e.g., for UI purposes). It may contain only
46 // hosted apps. See crbug.com/102533.
48 // 2. An extension can show up in multiple processes. That is why there is no
49 // GetExtensionProcess() method here. There are two cases: a) The extension
50 // is actually a hosted app, in which case this is normal, or b) there is an
51 // incognito window open and the extension is "split mode". It is *not safe*
52 // to assume that there is one process per extension. If you only care about
53 // extensions (not hosted apps), and you are on the UI thread, and you don't
54 // care about incognito version of this extension (or vice versa if you're in
55 // an incognito profile) then use
56 // ExtensionProcessManager::GetSiteInstanceForURL()->[Has|Get]Process().
58 // 3. The process ids contained in this class are *not limited* to the Profile
59 // you got this map from. They can also be associated with that profile's
60 // incognito/normal twin. If you care about this, use
61 // RenderProcessHost::FromID() and check the profile of the resulting object.
63 // TODO(aa): The above warnings suggest this class could use improvement :).
64 class ProcessMap {
65 public:
66 ProcessMap();
67 ~ProcessMap();
69 size_t size() const { return items_.size(); }
71 bool Insert(const std::string& extension_id, int process_id,
72 int site_instance_id);
74 bool Remove(const std::string& extension_id, int process_id,
75 int site_instance_id);
76 int RemoveAllFromProcess(int process_id);
78 bool Contains(const std::string& extension_id, int process_id) const;
79 bool Contains(int process_id) const;
81 std::set<std::string> GetExtensionsInProcess(int process_id) const;
83 private:
84 struct Item;
86 typedef std::set<Item> ItemSet;
87 ItemSet items_;
89 DISALLOW_COPY_AND_ASSIGN(ProcessMap);
92 } // extensions
94 #endif // CHROME_BROWSER_EXTENSIONS_PROCESS_MAP_H_