[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "chrome/browser/extensions/extension_info_map.h" | ||||
6 | |||||
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 7 | #include "chrome/common/extensions/extension.h" |
[email protected] | 5f945a0e | 2011-03-01 17:47:53 | [diff] [blame] | 8 | #include "content/browser/browser_thread.h" |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 9 | |
10 | namespace { | ||||
11 | |||||
12 | static void CheckOnValidThread() { | ||||
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 13 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 14 | } |
15 | |||||
16 | } // namespace | ||||
17 | |||||
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 18 | |
19 | struct ExtensionInfoMap::ExtraData { | ||||
20 | // When the extension was installed. | ||||
21 | base::Time install_time; | ||||
22 | |||||
23 | // True if the user has allowed this extension to run in incognito mode. | ||||
24 | bool incognito_enabled; | ||||
25 | |||||
26 | ExtraData(); | ||||
27 | ~ExtraData(); | ||||
28 | }; | ||||
29 | |||||
30 | ExtensionInfoMap::ExtraData::ExtraData() : incognito_enabled(false) { | ||||
31 | } | ||||
32 | |||||
33 | ExtensionInfoMap::ExtraData::~ExtraData() { | ||||
34 | } | ||||
35 | |||||
36 | |||||
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 37 | ExtensionInfoMap::ExtensionInfoMap() { |
38 | } | ||||
39 | |||||
40 | ExtensionInfoMap::~ExtensionInfoMap() { | ||||
41 | } | ||||
42 | |||||
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 43 | void ExtensionInfoMap::AddExtension(const Extension* extension, |
44 | base::Time install_time, | ||||
45 | bool incognito_enabled) { | ||||
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 46 | CheckOnValidThread(); |
[email protected] | be0a2cfd | 2011-06-02 21:36:42 | [diff] [blame] | 47 | extensions_.Insert(extension); |
48 | disabled_extensions_.Remove(extension->id()); | ||||
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 49 | |
50 | extra_data_[extension->id()].install_time = install_time; | ||||
51 | extra_data_[extension->id()].incognito_enabled = incognito_enabled; | ||||
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 52 | } |
53 | |||||
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 54 | void ExtensionInfoMap::RemoveExtension(const std::string& extension_id, |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 55 | const extension_misc::UnloadedExtensionReason reason) { |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 56 | CheckOnValidThread(); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 57 | const Extension* extension = extensions_.GetByID(extension_id); |
58 | extra_data_.erase(extension_id); // we don't care about disabled extra data | ||||
[email protected] | be0a2cfd | 2011-06-02 21:36:42 | [diff] [blame] | 59 | if (extension) { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 60 | if (reason == extension_misc::UNLOAD_REASON_DISABLE) |
[email protected] | be0a2cfd | 2011-06-02 21:36:42 | [diff] [blame] | 61 | disabled_extensions_.Insert(extension); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 62 | extensions_.Remove(extension_id); |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 63 | } else if (reason != extension_misc::UNLOAD_REASON_DISABLE) { |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 64 | // If the extension was uninstalled, make sure it's removed from the map of |
65 | // disabled extensions. | ||||
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 66 | disabled_extensions_.Remove(extension_id); |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 67 | } else { |
68 | // NOTE: This can currently happen if we receive multiple unload | ||||
69 | // notifications, e.g. setting incognito-enabled state for a | ||||
70 | // disabled extension (e.g., via sync). See | ||||
71 | // http://code.google.com/p/chromium/issues/detail?id=50582 . | ||||
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 72 | NOTREACHED() << extension_id; |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 73 | } |
74 | } | ||||
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 75 | |
76 | base::Time ExtensionInfoMap::GetInstallTime( | ||||
77 | const std::string& extension_id) const { | ||||
78 | ExtraDataMap::const_iterator iter = extra_data_.find(extension_id); | ||||
79 | if (iter != extra_data_.end()) | ||||
80 | return iter->second.install_time; | ||||
81 | return base::Time(); | ||||
82 | } | ||||
83 | |||||
84 | bool ExtensionInfoMap::IsIncognitoEnabled( | ||||
85 | const std::string& extension_id) const { | ||||
86 | ExtraDataMap::const_iterator iter = extra_data_.find(extension_id); | ||||
87 | if (iter != extra_data_.end()) | ||||
88 | return iter->second.incognito_enabled; | ||||
89 | return false; | ||||
90 | } | ||||
91 | |||||
92 | bool ExtensionInfoMap::CanCrossIncognito(const Extension* extension) { | ||||
93 | // This is duplicated from ExtensionService :(. | ||||
94 | return IsIncognitoEnabled(extension->id()) && | ||||
95 | !extension->incognito_split_mode(); | ||||
96 | } | ||||
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame^] | 97 | |
98 | // These are duplicated from ExtensionProcessManager :(. | ||||
99 | void ExtensionInfoMap::BindingsEnabledForProcess(int host_id) { | ||||
100 | extension_bindings_process_ids_.insert(host_id); | ||||
101 | } | ||||
102 | |||||
103 | void ExtensionInfoMap::BindingsDisabledForProcess(int host_id) { | ||||
104 | extension_bindings_process_ids_.erase(host_id); | ||||
105 | } | ||||
106 | |||||
107 | bool ExtensionInfoMap::AreBindingsEnabledForProcess(int host_id) const { | ||||
108 | return extension_bindings_process_ids_.find(host_id) != | ||||
109 | extension_bindings_process_ids_.end(); | ||||
110 | } |