Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3295)

Unified Diff: chrome/browser/extensions/api/declarative/rules_registry_service.h

Issue 9315010: RulesRegistry for declarative APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implemented ID and priority generation Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/declarative/rules_registry_service.h
diff --git a/chrome/browser/extensions/api/declarative/rules_registry_service.h b/chrome/browser/extensions/api/declarative/rules_registry_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..0066df7e23a35160450d159b3bafe8dbd36b699d
--- /dev/null
+++ b/chrome/browser/extensions/api/declarative/rules_registry_service.h
@@ -0,0 +1,110 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
+#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
+#pragma once
+
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/api/declarative/rules_registry.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+class Profile;
+
+namespace extensions {
+class RuleIdentifier;
+}
+
+namespace content {
+class NotificationSource;
+class NotificationSource;
+}
+
+namespace extensions {
+
+// This is a dispatcher that delegates function calls to other RuleRegistries.
+// Use the RulesRegistryServiceFactory to retrieve an instance of this class.
not at google - send to devlin 2012/02/02 11:59:16 Why the need for RulesRegistryServiceFactory? Can
battre 2012/02/02 19:12:36 I raised this concern in a previous Patch Set vers
Aaron Boodman 2012/02/03 18:04:51 It is OK to add members to ExtensionService right
+class RulesRegistryService
+ : public ProfileKeyedService, content::NotificationObserver {
+ public:
+ RulesRegistryService();
+ virtual ~RulesRegistryService();
+ void Init(Profile* profile);
+
+ // Registers a RuleRegistry such that all calls for |event_name| are
+ // dispatched to this RuleRegistry.
+ // Public for testing.
+ void RegisterRuleRegistry(
not at google - send to devlin 2012/02/02 11:59:16 s/Rule/Rules/
battre 2012/02/02 19:12:36 Done.
+ const std::string& event_name,
+ scoped_ptr<RulesRegistry> rule_registry);
+
+ // RulesRegistry alike implementation. We add an additional |event_name|
+ // to each function, which represents the name of the JavaScript object
+ // on which the function was called.
not at google - send to devlin 2012/02/02 11:59:16 Is it possible to move much of the logic in this c
Aaron Boodman 2012/02/02 16:28:51 Feels like overdesign to use a decorator to add lo
Aaron Boodman 2012/02/02 16:30:25 Sorry, I meant to remove this paragraph. I think t
battre 2012/02/02 19:12:36 At first I considered this overdesign as well. But
+ bool AddRules(const std::string& event_name,
+ const std::string& extension_id,
+ const std::vector<DictionaryValue*>& rules,
+ RulesRegistry::SetErrorCallback set_error_callback);
+ bool RemoveRules(const std::string& event_name,
+ const std::string& extension_id,
+ const std::vector<std::string>& rule_identifiers,
+ RulesRegistry::SetErrorCallback set_error_callback);
+ void GetRules(const std::string& event_name,
+ const std::string& extension_id,
+ const std::vector<std::string>& rule_identifiers,
+ std::vector<DictionaryValue*>* out);
+ void OnExtensionUnloaded(const std::string& extension_id);
+
+ private:
+ // Maps event names to RuleRegistries that handle these events.
+ // Owns the RuleRegistry objects.
+ typedef std::map<std::string, RulesRegistry*> RulesRegistryMap;
+
+ // Returns whether any existing rule is registered with identifier |id|.
+ bool IsUniqueId(const RuleIdentifier& id) const;
+
+ // Creates a ID that is unique within the scope of
+ // (|extension_id|, |event_name|).
+ std::string GenerateUniqueId(std::string extension_id,
+ std::string event_name);
+
+ // Verifies that all |rules| have unique IDs or initializes them with
+ // unique IDs if they don't have one. In case of duplicate IDs, this function
+ // calls |set_error_callback| and returns false.
+ bool CheckAndFillInOptionalRules(
+ const std::string& event_name,
+ const std::string& extension_id,
+ const std::vector<DictionaryValue*>& rules,
+ RulesRegistry::SetErrorCallback set_error_callback);
+
+ // Initializes the priority fields in case they have not been set.
+ void FillInOptionalPriorities(const std::vector<DictionaryValue*>& rules);
+
+ // Implementation of content::NotificationObserver.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ content::NotificationRegistrar registrar_;
+
+ RulesRegistryMap rule_registries_;
+
+ std::set<RuleIdentifier> used_rule_identifiers_;
+ int last_generated_rule_identifier_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(RulesRegistryService);
+};
+
+}
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__

Powered by Google App Engine
This is Rietveld 408576698