| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/extension_settings_api.h" | 8 #include "chrome/browser/extensions/extension_settings_api.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 const char* kUnsupportedArgumentType = "Unsupported argument type"; | 13 const char* kUnsupportedArgumentType = "Unsupported argument type"; |
| 14 } // namespace | 14 } // namespace |
| 15 | 15 |
| 16 // SettingsFunction | 16 // SettingsFunction |
| 17 | 17 |
| 18 bool SettingsFunction::RunImpl() { | 18 bool SettingsFunction::RunImpl() { |
| 19 BrowserThread::PostTask( | 19 profile()->GetExtensionService()->extension_settings()->RunWithStorage( |
| 20 BrowserThread::FILE, | 20 extension_id(), |
| 21 FROM_HERE, | 21 base::Bind(&SettingsFunction::RunWithStorageOnFileThread, this)); |
| 22 base::Bind(&SettingsFunction::RunOnFileThread, this)); | |
| 23 return true; | 22 return true; |
| 24 } | 23 } |
| 25 | 24 |
| 26 void SettingsFunction::RunOnFileThread() { | 25 void SettingsFunction::RunWithStorageOnFileThread( |
| 26 ExtensionSettingsStorage* storage) { |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 28 ExtensionSettings* settings = | 28 bool success = RunWithStorage(storage); |
| 29 profile()->GetExtensionService()->extension_settings(); | |
| 30 bool success = RunWithStorage(settings->GetStorage(extension_id())); | |
| 31 BrowserThread::PostTask( | 29 BrowserThread::PostTask( |
| 32 BrowserThread::UI, | 30 BrowserThread::UI, |
| 33 FROM_HERE, | 31 FROM_HERE, |
| 34 base::Bind(&SettingsFunction::SendResponse, this, success)); | 32 base::Bind(&SettingsFunction::SendResponse, this, success)); |
| 35 } | 33 } |
| 36 | 34 |
| 37 bool SettingsFunction::UseResult( | 35 bool SettingsFunction::UseResult( |
| 38 const ExtensionSettingsStorage::Result& storage_result) { | 36 const ExtensionSettingsStorage::Result& storage_result) { |
| 39 if (storage_result.HasError()) { | 37 if (storage_result.HasError()) { |
| 40 error_ = storage_result.GetError(); | 38 error_ = storage_result.GetError(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 AddAllStringValues(*as_list, &string_list); | 95 AddAllStringValues(*as_list, &string_list); |
| 98 return UseResult(storage->Remove(string_list)); | 96 return UseResult(storage->Remove(string_list)); |
| 99 } | 97 } |
| 100 return UseResult(ExtensionSettingsStorage::Result(kUnsupportedArgumentType)); | 98 return UseResult(ExtensionSettingsStorage::Result(kUnsupportedArgumentType)); |
| 101 } | 99 } |
| 102 | 100 |
| 103 bool ClearSettingsFunction::RunWithStorage( | 101 bool ClearSettingsFunction::RunWithStorage( |
| 104 ExtensionSettingsStorage* storage) { | 102 ExtensionSettingsStorage* storage) { |
| 105 return UseResult(storage->Clear()); | 103 return UseResult(storage->Clear()); |
| 106 } | 104 } |
| OLD | NEW |