OLD | NEW |
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 #include "chrome/browser/extensions/extension_info_map.h" | 5 #include "chrome/browser/extensions/extension_info_map.h" |
6 | 6 |
7 #include "chrome/common/extensions/extension.h" | 7 #include "chrome/common/extensions/extension.h" |
8 #include "content/browser/browser_thread.h" | 8 #include "content/browser/browser_thread.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 static void CheckOnValidThread() { | 12 static void CheckOnValidThread() { |
13 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 13 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
14 } | 14 } |
15 | 15 |
16 } // namespace | 16 } // namespace |
17 | 17 |
| 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 |
18 ExtensionInfoMap::ExtensionInfoMap() { | 37 ExtensionInfoMap::ExtensionInfoMap() { |
19 } | 38 } |
20 | 39 |
21 ExtensionInfoMap::~ExtensionInfoMap() { | 40 ExtensionInfoMap::~ExtensionInfoMap() { |
22 } | 41 } |
23 | 42 |
24 void ExtensionInfoMap::AddExtension(const Extension* extension) { | 43 void ExtensionInfoMap::AddExtension(const Extension* extension, |
| 44 base::Time install_time, |
| 45 bool incognito_enabled) { |
25 CheckOnValidThread(); | 46 CheckOnValidThread(); |
26 extensions_.Insert(extension); | 47 extensions_.Insert(extension); |
27 disabled_extensions_.Remove(extension->id()); | 48 disabled_extensions_.Remove(extension->id()); |
| 49 |
| 50 extra_data_[extension->id()].install_time = install_time; |
| 51 extra_data_[extension->id()].incognito_enabled = incognito_enabled; |
28 } | 52 } |
29 | 53 |
30 void ExtensionInfoMap::RemoveExtension(const std::string& id, | 54 void ExtensionInfoMap::RemoveExtension(const std::string& extension_id, |
31 const UnloadedExtensionInfo::Reason reason) { | 55 const UnloadedExtensionInfo::Reason reason) { |
32 CheckOnValidThread(); | 56 CheckOnValidThread(); |
33 const Extension* extension = extensions_.GetByID(id); | 57 const Extension* extension = extensions_.GetByID(extension_id); |
| 58 extra_data_.erase(extension_id); // we don't care about disabled extra data |
34 if (extension) { | 59 if (extension) { |
35 if (reason == UnloadedExtensionInfo::DISABLE) | 60 if (reason == UnloadedExtensionInfo::DISABLE) |
36 disabled_extensions_.Insert(extension); | 61 disabled_extensions_.Insert(extension); |
37 extensions_.Remove(id); | 62 extensions_.Remove(extension_id); |
38 } else if (reason != UnloadedExtensionInfo::DISABLE) { | 63 } else if (reason != UnloadedExtensionInfo::DISABLE) { |
39 // If the extension was uninstalled, make sure it's removed from the map of | 64 // If the extension was uninstalled, make sure it's removed from the map of |
40 // disabled extensions. | 65 // disabled extensions. |
41 disabled_extensions_.Remove(id); | 66 disabled_extensions_.Remove(extension_id); |
42 } else { | 67 } else { |
43 // NOTE: This can currently happen if we receive multiple unload | 68 // NOTE: This can currently happen if we receive multiple unload |
44 // notifications, e.g. setting incognito-enabled state for a | 69 // notifications, e.g. setting incognito-enabled state for a |
45 // disabled extension (e.g., via sync). See | 70 // disabled extension (e.g., via sync). See |
46 // http://code.google.com/p/chromium/issues/detail?id=50582 . | 71 // http://code.google.com/p/chromium/issues/detail?id=50582 . |
47 NOTREACHED() << id; | 72 NOTREACHED() << extension_id; |
48 } | 73 } |
49 } | 74 } |
| 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 } |
OLD | NEW |