| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/settings/settings_api.h" | 5 #include "chrome/browser/extensions/settings/settings_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" |
| 11 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extensions_quota_service.h" | 15 #include "chrome/browser/extensions/extensions_quota_service.h" |
| 15 #include "chrome/browser/extensions/settings/settings_frontend.h" | 16 #include "chrome/browser/extensions/settings/settings_frontend.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/api/storage.h" | 19 #include "chrome/common/extensions/api/storage.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 | 21 |
| 20 namespace extensions { | 22 namespace extensions { |
| 21 | 23 |
| 22 using content::BrowserThread; | 24 using content::BrowserThread; |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 const char kUnsupportedArgumentType[] = "Unsupported argument type"; | 27 const char kUnsupportedArgumentType[] = "Unsupported argument type"; |
| 26 const char kInvalidNamespaceErrorMessage[] = | 28 const char kInvalidNamespaceErrorMessage[] = |
| 27 "\"%s\" is not available in this instance of Chrome"; | 29 "\"%s\" is not available in this instance of Chrome"; |
| 30 const char kManagedNamespaceDisabledErrorMessage[] = |
| 31 "\"managed\" is disabled. Use \"--%s\" to enable it."; |
| 28 const char kStorageErrorMessage[] = "Storage error"; | 32 const char kStorageErrorMessage[] = "Storage error"; |
| 29 } // namespace | 33 } // namespace |
| 30 | 34 |
| 31 // SettingsFunction | 35 // SettingsFunction |
| 32 | 36 |
| 33 SettingsFunction::SettingsFunction() | 37 SettingsFunction::SettingsFunction() |
| 34 : settings_namespace_(settings_namespace::INVALID) {} | 38 : settings_namespace_(settings_namespace::INVALID) {} |
| 35 | 39 |
| 36 SettingsFunction::~SettingsFunction() {} | 40 SettingsFunction::~SettingsFunction() {} |
| 37 | 41 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 48 | 52 |
| 49 bool SettingsFunction::RunImpl() { | 53 bool SettingsFunction::RunImpl() { |
| 50 std::string settings_namespace_string; | 54 std::string settings_namespace_string; |
| 51 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &settings_namespace_string)); | 55 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &settings_namespace_string)); |
| 52 args_->Remove(0, NULL); | 56 args_->Remove(0, NULL); |
| 53 settings_namespace_ = | 57 settings_namespace_ = |
| 54 settings_namespace::FromString(settings_namespace_string); | 58 settings_namespace::FromString(settings_namespace_string); |
| 55 EXTENSION_FUNCTION_VALIDATE( | 59 EXTENSION_FUNCTION_VALIDATE( |
| 56 settings_namespace_ != settings_namespace::INVALID); | 60 settings_namespace_ != settings_namespace::INVALID); |
| 57 | 61 |
| 62 // TODO(joaodasilva): remove this flag once policy for extensions works on |
| 63 // mac and chromeos. |
| 64 if (settings_namespace_ == settings_namespace::MANAGED && |
| 65 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 66 switches::kEnableManagedStorage)) { |
| 67 error_ = base::StringPrintf(kManagedNamespaceDisabledErrorMessage, |
| 68 switches::kEnableManagedStorage); |
| 69 return false; |
| 70 } |
| 71 |
| 58 SettingsFrontend* frontend = | 72 SettingsFrontend* frontend = |
| 59 profile()->GetExtensionService()->settings_frontend(); | 73 profile()->GetExtensionService()->settings_frontend(); |
| 60 if (!frontend->IsStorageEnabled(settings_namespace_)) { | 74 if (!frontend->IsStorageEnabled(settings_namespace_)) { |
| 61 error_ = base::StringPrintf(kInvalidNamespaceErrorMessage, | 75 error_ = base::StringPrintf(kInvalidNamespaceErrorMessage, |
| 62 settings_namespace_string.c_str()); | 76 settings_namespace_string.c_str()); |
| 63 return false; | 77 return false; |
| 64 } | 78 } |
| 65 | 79 |
| 66 observers_ = frontend->GetObservers(); | 80 observers_ = frontend->GetObservers(); |
| 67 frontend->RunWithStorage( | 81 frontend->RunWithStorage( |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 bool ClearSettingsFunction::RunWithStorage(ValueStore* storage) { | 286 bool ClearSettingsFunction::RunWithStorage(ValueStore* storage) { |
| 273 return UseWriteResult(storage->Clear()); | 287 return UseWriteResult(storage->Clear()); |
| 274 } | 288 } |
| 275 | 289 |
| 276 void ClearSettingsFunction::GetQuotaLimitHeuristics( | 290 void ClearSettingsFunction::GetQuotaLimitHeuristics( |
| 277 QuotaLimitHeuristics* heuristics) const { | 291 QuotaLimitHeuristics* heuristics) const { |
| 278 GetModificationQuotaLimitHeuristics(heuristics); | 292 GetModificationQuotaLimitHeuristics(heuristics); |
| 279 } | 293 } |
| 280 | 294 |
| 281 } // namespace extensions | 295 } // namespace extensions |
| OLD | NEW |