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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.cc

Issue 9820003: Implementation of beginning of Declarative Web Request API backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pacify clang Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h "
6
7 #include "base/logging.h"
8 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action .h"
9 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h"
10
11 namespace extensions {
12
13 WebRequestRule::WebRequestRule(
14 const GlobalRuleId& id,
15 scoped_ptr<WebRequestConditionSet> conditions,
16 scoped_ptr<WebRequestActionSet> actions)
17 : id_(id),
18 conditions_(conditions.release()),
19 actions_(actions.release()) {
20 CHECK(conditions_.get());
21 CHECK(actions_.get());
22 }
23
24 WebRequestRule::~WebRequestRule() {}
25
26 // static
27 bool WebRequestRule::CheckConsistency(
28 WebRequestConditionSet* conditions,
29 WebRequestActionSet* actions,
30 std::string* error) {
31 // TODO(battre): Implement this.
32 return true;
33 }
34
35 // static
36 scoped_ptr<WebRequestRule> WebRequestRule::Create(
37 URLMatcherConditionFactory* url_matcher_condition_factory,
38 const std::string& extension_id,
39 linked_ptr<RulesRegistry::Rule> rule,
40 std::string* error) {
41 scoped_ptr<WebRequestRule> error_result;
42
43 scoped_ptr<WebRequestConditionSet> conditions =
44 WebRequestConditionSet::Create(
45 url_matcher_condition_factory, rule->conditions, error);
46 if (!error->empty())
47 return error_result.Pass();
48 CHECK(conditions.get());
49
50 scoped_ptr<WebRequestActionSet> actions =
51 WebRequestActionSet::Create(rule->actions, error);
52 if (!error->empty())
53 return error_result.Pass();
54 CHECK(actions.get());
55
56 if (!CheckConsistency(conditions.get(), actions.get(), error)) {
57 DCHECK(!error->empty());
58 return error_result.Pass();
59 }
60
61 GlobalRuleId rule_id = make_pair(extension_id, *(rule->id));
62 return scoped_ptr<WebRequestRule>(
63 new WebRequestRule(rule_id, conditions.Pass(), actions.Pass()));
64 }
65
66 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698