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()->RunWithSettings( |
20 BrowserThread::FILE, | 20 base::Bind(&SettingsFunction::RunWithSettingsOnFileThread, this)); |
21 FROM_HERE, | |
22 base::Bind(&SettingsFunction::RunOnFileThread, this)); | |
23 return true; | 21 return true; |
24 } | 22 } |
25 | 23 |
26 void SettingsFunction::RunOnFileThread() { | 24 void SettingsFunction::RunWithSettingsOnFileThread( |
| 25 ExtensionSettings* settings) { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
28 ExtensionSettings* settings = | |
29 profile()->GetExtensionService()->extension_settings(); | |
30 bool success = RunWithStorage(settings->GetStorage(extension_id())); | 27 bool success = RunWithStorage(settings->GetStorage(extension_id())); |
31 BrowserThread::PostTask( | 28 BrowserThread::PostTask( |
32 BrowserThread::UI, | 29 BrowserThread::UI, |
33 FROM_HERE, | 30 FROM_HERE, |
34 base::Bind(&SettingsFunction::SendResponse, this, success)); | 31 base::Bind(&SettingsFunction::SendResponse, this, success)); |
35 } | 32 } |
36 | 33 |
37 bool SettingsFunction::UseResult( | 34 bool SettingsFunction::UseResult( |
38 const ExtensionSettingsStorage::Result& storage_result) { | 35 const ExtensionSettingsStorage::Result& storage_result) { |
39 if (storage_result.HasError()) { | 36 if (storage_result.HasError()) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 AddAllStringValues(*as_list, &string_list); | 94 AddAllStringValues(*as_list, &string_list); |
98 return UseResult(storage->Remove(string_list)); | 95 return UseResult(storage->Remove(string_list)); |
99 } | 96 } |
100 return UseResult(ExtensionSettingsStorage::Result(kUnsupportedArgumentType)); | 97 return UseResult(ExtensionSettingsStorage::Result(kUnsupportedArgumentType)); |
101 } | 98 } |
102 | 99 |
103 bool ClearSettingsFunction::RunWithStorage( | 100 bool ClearSettingsFunction::RunWithStorage( |
104 ExtensionSettingsStorage* storage) { | 101 ExtensionSettingsStorage* storage) { |
105 return UseResult(storage->Clear()); | 102 return UseResult(storage->Clear()); |
106 } | 103 } |
OLD | NEW |