| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ | 5 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ |
| 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ | 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <set> | 9 #include <set> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 class BrowserContext; | 17 class BrowserContext; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 class RulesRegistry; | 22 class RulesRegistry; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 // Returns a key for the state store. The associated preference is a boolean | 35 // Returns a key for the state store. The associated preference is a boolean |
| 36 // indicating whether there are some declarative rules stored in the rule | 36 // indicating whether there are some declarative rules stored in the rule |
| 37 // store. | 37 // store. |
| 38 static std::string GetRulesStoredKey(const std::string& event_name, | 38 static std::string GetRulesStoredKey(const std::string& event_name, |
| 39 bool incognito); | 39 bool incognito); |
| 40 | 40 |
| 41 // Initialize the storage functionality. | 41 // Initialize the storage functionality. |
| 42 void Init(RulesRegistry* registry); | 42 void Init(RulesRegistry* registry); |
| 43 | 43 |
| 44 void WriteToStorage(const std::string& extension_id, | 44 void WriteToStorage(const std::string& extension_id, |
| 45 scoped_ptr<base::Value> value); | 45 std::unique_ptr<base::Value> value); |
| 46 | 46 |
| 47 base::WeakPtr<RulesCacheDelegate> GetWeakPtr() { | 47 base::WeakPtr<RulesCacheDelegate> GetWeakPtr() { |
| 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 49 return weak_ptr_factory_.GetWeakPtr(); | 49 return weak_ptr_factory_.GetWeakPtr(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 FRIEND_TEST_ALL_PREFIXES(RulesRegistryWithCacheTest, | 53 FRIEND_TEST_ALL_PREFIXES(RulesRegistryWithCacheTest, |
| 54 DeclarativeRulesStored); | 54 DeclarativeRulesStored); |
| 55 FRIEND_TEST_ALL_PREFIXES(RulesRegistryWithCacheTest, | 55 FRIEND_TEST_ALL_PREFIXES(RulesRegistryWithCacheTest, |
| 56 RulesStoredFlagMultipleRegistries); | 56 RulesStoredFlagMultipleRegistries); |
| 57 | 57 |
| 58 static const char kRulesStoredKey[]; | 58 static const char kRulesStoredKey[]; |
| 59 | 59 |
| 60 // Check if we are done reading all data from storage on startup, and notify | 60 // Check if we are done reading all data from storage on startup, and notify |
| 61 // the RulesRegistry on its thread if so. The notification is delivered | 61 // the RulesRegistry on its thread if so. The notification is delivered |
| 62 // exactly once. | 62 // exactly once. |
| 63 void CheckIfReady(); | 63 void CheckIfReady(); |
| 64 | 64 |
| 65 // Schedules retrieving rules for already loaded extensions where | 65 // Schedules retrieving rules for already loaded extensions where |
| 66 // appropriate. | 66 // appropriate. |
| 67 void ReadRulesForInstalledExtensions(); | 67 void ReadRulesForInstalledExtensions(); |
| 68 | 68 |
| 69 // Read/write a list of rules serialized to Values. | 69 // Read/write a list of rules serialized to Values. |
| 70 void ReadFromStorage(const std::string& extension_id); | 70 void ReadFromStorage(const std::string& extension_id); |
| 71 void ReadFromStorageCallback(const std::string& extension_id, | 71 void ReadFromStorageCallback(const std::string& extension_id, |
| 72 scoped_ptr<base::Value> value); | 72 std::unique_ptr<base::Value> value); |
| 73 | 73 |
| 74 // Check the preferences whether the extension with |extension_id| has some | 74 // Check the preferences whether the extension with |extension_id| has some |
| 75 // rules stored on disk. If this information is not in the preferences, true | 75 // rules stored on disk. If this information is not in the preferences, true |
| 76 // is returned as a safe default value. | 76 // is returned as a safe default value. |
| 77 bool GetDeclarativeRulesStored(const std::string& extension_id) const; | 77 bool GetDeclarativeRulesStored(const std::string& extension_id) const; |
| 78 // Modify the preference to |rules_stored|. | 78 // Modify the preference to |rules_stored|. |
| 79 void SetDeclarativeRulesStored(const std::string& extension_id, | 79 void SetDeclarativeRulesStored(const std::string& extension_id, |
| 80 bool rules_stored); | 80 bool rules_stored); |
| 81 | 81 |
| 82 content::BrowserContext* browser_context_; | 82 content::BrowserContext* browser_context_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 104 // We notified the RulesRegistry that the rules are loaded. | 104 // We notified the RulesRegistry that the rules are loaded. |
| 105 bool notified_registry_; | 105 bool notified_registry_; |
| 106 | 106 |
| 107 // Use this factory to generate weak pointers bound to the UI thread. | 107 // Use this factory to generate weak pointers bound to the UI thread. |
| 108 base::WeakPtrFactory<RulesCacheDelegate> weak_ptr_factory_; | 108 base::WeakPtrFactory<RulesCacheDelegate> weak_ptr_factory_; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 } // namespace extensions | 111 } // namespace extensions |
| 112 | 112 |
| 113 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ | 113 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ |
| OLD | NEW |