OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/storage/storage_api.h" | 5 #include "extensions/browser/api/storage/storage_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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 : settings_namespace_(settings_namespace::INVALID), | 25 : settings_namespace_(settings_namespace::INVALID), |
26 tried_restoring_storage_(false) {} | 26 tried_restoring_storage_(false) {} |
27 | 27 |
28 SettingsFunction::~SettingsFunction() {} | 28 SettingsFunction::~SettingsFunction() {} |
29 | 29 |
30 bool SettingsFunction::ShouldSkipQuotaLimiting() const { | 30 bool SettingsFunction::ShouldSkipQuotaLimiting() const { |
31 // Only apply quota if this is for sync storage. | 31 // Only apply quota if this is for sync storage. |
32 std::string settings_namespace_string; | 32 std::string settings_namespace_string; |
33 if (!args_->GetString(0, &settings_namespace_string)) { | 33 if (!args_->GetString(0, &settings_namespace_string)) { |
34 // This should be EXTENSION_FUNCTION_VALIDATE(false) but there is no way | 34 // This should be EXTENSION_FUNCTION_VALIDATE(false) but there is no way |
35 // to signify that from this function. It will be caught in | 35 // to signify that from this function. It will be caught in Run(). |
36 // RunImplTypesafe(). | |
37 return false; | 36 return false; |
38 } | 37 } |
39 return settings_namespace_string != "sync"; | 38 return settings_namespace_string != "sync"; |
40 } | 39 } |
41 | 40 |
42 ExtensionFunction::ResponseAction SettingsFunction::RunImplTypesafe() { | 41 ExtensionFunction::ResponseAction SettingsFunction::Run() { |
43 std::string settings_namespace_string; | 42 std::string settings_namespace_string; |
44 EXTENSION_FUNCTION_VALIDATE_TYPESAFE( | 43 EXTENSION_FUNCTION_VALIDATE_TYPESAFE( |
45 args_->GetString(0, &settings_namespace_string)); | 44 args_->GetString(0, &settings_namespace_string)); |
46 args_->Remove(0, NULL); | 45 args_->Remove(0, NULL); |
47 settings_namespace_ = | 46 settings_namespace_ = |
48 settings_namespace::FromString(settings_namespace_string); | 47 settings_namespace::FromString(settings_namespace_string); |
49 EXTENSION_FUNCTION_VALIDATE_TYPESAFE(settings_namespace_ != | 48 EXTENSION_FUNCTION_VALIDATE_TYPESAFE(settings_namespace_ != |
50 settings_namespace::INVALID); | 49 settings_namespace::INVALID); |
51 | 50 |
52 StorageFrontend* frontend = StorageFrontend::Get(browser_context()); | 51 StorageFrontend* frontend = StorageFrontend::Get(browser_context()); |
53 if (!frontend->IsStorageEnabled(settings_namespace_)) { | 52 if (!frontend->IsStorageEnabled(settings_namespace_)) { |
54 return RespondNow(Error( | 53 return RespondNow(Error( |
55 base::StringPrintf("\"%s\" is not available in this instance of Chrome", | 54 base::StringPrintf("\"%s\" is not available in this instance of Chrome", |
56 settings_namespace_string.c_str()))); | 55 settings_namespace_string.c_str()))); |
57 } | 56 } |
58 | 57 |
59 observers_ = frontend->GetObservers(); | 58 observers_ = frontend->GetObservers(); |
60 frontend->RunWithStorage( | 59 frontend->RunWithStorage( |
61 GetExtension(), | 60 GetExtension(), |
62 settings_namespace_, | 61 settings_namespace_, |
63 base::Bind(&SettingsFunction::AsyncRunWithStorage, this)); | 62 base::Bind(&SettingsFunction::AsyncRunWithStorage, this)); |
64 return RespondLater(); | 63 return RespondLater(); |
65 } | 64 } |
66 | 65 |
67 void SettingsFunction::AsyncRunWithStorage(ValueStore* storage) { | 66 void SettingsFunction::AsyncRunWithStorage(ValueStore* storage) { |
68 ResponseValue response = RunWithStorage(storage); | 67 ResponseValue response = RunWithStorage(storage); |
69 BrowserThread::PostTask(BrowserThread::UI, | 68 BrowserThread::PostTask( |
70 FROM_HERE, | 69 BrowserThread::UI, |
71 base::Bind(&SettingsFunction::SendResponseTypesafe, | 70 FROM_HERE, |
72 this, | 71 base::Bind(&SettingsFunction::Done, this, base::Passed(&response))); |
73 base::Passed(&response))); | |
74 } | 72 } |
75 | 73 |
76 ExtensionFunction::ResponseValue SettingsFunction::UseReadResult( | 74 ExtensionFunction::ResponseValue SettingsFunction::UseReadResult( |
77 ValueStore::ReadResult result, | 75 ValueStore::ReadResult result, |
78 ValueStore* storage) { | 76 ValueStore* storage) { |
79 if (result->HasError()) | 77 if (result->HasError()) |
80 return HandleError(result->error(), storage); | 78 return HandleError(result->error(), storage); |
81 | 79 |
82 base::DictionaryValue* dict = new base::DictionaryValue(); | 80 base::DictionaryValue* dict = new base::DictionaryValue(); |
83 dict->Swap(&result->settings()); | 81 dict->Swap(&result->settings()); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 StorageStorageAreaClearFunction::RunWithStorage(ValueStore* storage) { | 301 StorageStorageAreaClearFunction::RunWithStorage(ValueStore* storage) { |
304 return UseWriteResult(storage->Clear(), storage); | 302 return UseWriteResult(storage->Clear(), storage); |
305 } | 303 } |
306 | 304 |
307 void StorageStorageAreaClearFunction::GetQuotaLimitHeuristics( | 305 void StorageStorageAreaClearFunction::GetQuotaLimitHeuristics( |
308 QuotaLimitHeuristics* heuristics) const { | 306 QuotaLimitHeuristics* heuristics) const { |
309 GetModificationQuotaLimitHeuristics(heuristics); | 307 GetModificationQuotaLimitHeuristics(heuristics); |
310 } | 308 } |
311 | 309 |
312 } // namespace extensions | 310 } // namespace extensions |
OLD | NEW |