| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/lazy_instance.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 14 #include "base/singleton.h" | |
| 15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "base/task.h" | 18 #include "base/task.h" |
| 19 #include "base/thread_restrictions.h" | 19 #include "base/thread_restrictions.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "base/version.h" | 21 #include "base/version.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/browser_thread.h" | 23 #include "chrome/browser/browser_thread.h" |
| 24 #include "chrome/browser/extensions/convert_user_script.h" | 24 #include "chrome/browser/extensions/convert_user_script.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 44 // would be necessary with PostMessage since file_util::Delete is overloaded. | 44 // would be necessary with PostMessage since file_util::Delete is overloaded. |
| 45 static void DeleteFileHelper(const FilePath& path, bool recursive) { | 45 static void DeleteFileHelper(const FilePath& path, bool recursive) { |
| 46 file_util::Delete(path, recursive); | 46 file_util::Delete(path, recursive); |
| 47 } | 47 } |
| 48 | 48 |
| 49 struct WhitelistedInstallData { | 49 struct WhitelistedInstallData { |
| 50 WhitelistedInstallData() {} | 50 WhitelistedInstallData() {} |
| 51 std::set<std::string> ids; | 51 std::set<std::string> ids; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 static base::LazyInstance<WhitelistedInstallData> |
| 55 g_whitelisted_install_data(base::LINKER_INITIALIZED); |
| 56 |
| 54 } // namespace | 57 } // namespace |
| 55 | 58 |
| 56 // static | 59 // static |
| 57 void CrxInstaller::SetWhitelistedInstallId(const std::string& id) { | 60 void CrxInstaller::SetWhitelistedInstallId(const std::string& id) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 59 Singleton<WhitelistedInstallData>::get()->ids.insert(id); | 62 g_whitelisted_install_data.Get().ids.insert(id); |
| 60 } | 63 } |
| 61 | 64 |
| 62 // static | 65 // static |
| 63 bool CrxInstaller::IsIdWhitelisted(const std::string& id) { | 66 bool CrxInstaller::IsIdWhitelisted(const std::string& id) { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 65 std::set<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids; | 68 std::set<std::string>& ids = g_whitelisted_install_data.Get().ids; |
| 66 return ContainsKey(ids, id); | 69 return ContainsKey(ids, id); |
| 67 } | 70 } |
| 68 | 71 |
| 69 // static | 72 // static |
| 70 bool CrxInstaller::ClearWhitelistedInstallId(const std::string& id) { | 73 bool CrxInstaller::ClearWhitelistedInstallId(const std::string& id) { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 72 std::set<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids; | 75 std::set<std::string>& ids = g_whitelisted_install_data.Get().ids; |
| 73 if (ContainsKey(ids, id)) { | 76 if (ContainsKey(ids, id)) { |
| 74 ids.erase(id); | 77 ids.erase(id); |
| 75 return true; | 78 return true; |
| 76 } | 79 } |
| 77 return false; | 80 return false; |
| 78 } | 81 } |
| 79 | 82 |
| 80 CrxInstaller::CrxInstaller(ExtensionsService* frontend, | 83 CrxInstaller::CrxInstaller(ExtensionsService* frontend, |
| 81 ExtensionInstallUI* client) | 84 ExtensionInstallUI* client) |
| 82 : install_directory_(frontend->install_directory()), | 85 : install_directory_(frontend->install_directory()), |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 client_->OnInstallSuccess(extension_.get()); | 434 client_->OnInstallSuccess(extension_.get()); |
| 432 | 435 |
| 433 // Tell the frontend about the installation and hand off ownership of | 436 // Tell the frontend about the installation and hand off ownership of |
| 434 // extension_ to it. | 437 // extension_ to it. |
| 435 frontend_->OnExtensionInstalled(extension_); | 438 frontend_->OnExtensionInstalled(extension_); |
| 436 extension_ = NULL; | 439 extension_ = NULL; |
| 437 | 440 |
| 438 // We're done. We don't post any more tasks to ourselves so we are deleted | 441 // We're done. We don't post any more tasks to ourselves so we are deleted |
| 439 // soon. | 442 // soon. |
| 440 } | 443 } |
| OLD | NEW |