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

Side by Side Diff: chrome/browser/extensions/api/declarative/declarative_api.cc

Issue 9416060: Move PostTaskAndReplyWithStatus into task_runner_helpers.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed copyright header Created 8 years, 8 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
« no previous file with comments | « chrome/browser/extensions/api/declarative/declarative_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/extensions/api/declarative/declarative_api.h" 5 #include "chrome/browser/extensions/api/declarative/declarative_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/task_runner_util.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" 11 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
11 #include "chrome/browser/extensions/extension_system_factory.h" 12 #include "chrome/browser/extensions/extension_system_factory.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/api/experimental.declarative.h" 14 #include "chrome/common/extensions/api/experimental.declarative.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 16
16 using extensions::api::experimental_declarative::Rule; 17 using extensions::api::experimental_declarative::Rule;
17 18
18 namespace AddRules = extensions::api::experimental_declarative::AddRules; 19 namespace AddRules = extensions::api::experimental_declarative::AddRules;
(...skipping 28 matching lines...) Expand all
47 48
48 RulesRegistryService* rules_registry_service = 49 RulesRegistryService* rules_registry_service =
49 ExtensionSystemFactory::GetForProfile(profile())-> 50 ExtensionSystemFactory::GetForProfile(profile())->
50 rules_registry_service(); 51 rules_registry_service();
51 rules_registry_ = rules_registry_service->GetRulesRegistry(event_name); 52 rules_registry_ = rules_registry_service->GetRulesRegistry(event_name);
52 // Raw access to this function is not available to extensions, therefore 53 // Raw access to this function is not available to extensions, therefore
53 // there should never be a request for a nonexisting rules registry. 54 // there should never be a request for a nonexisting rules registry.
54 EXTENSION_FUNCTION_VALIDATE(rules_registry_); 55 EXTENSION_FUNCTION_VALIDATE(rules_registry_);
55 56
56 if (content::BrowserThread::CurrentlyOn(rules_registry_->GetOwnerThread())) { 57 if (content::BrowserThread::CurrentlyOn(rules_registry_->GetOwnerThread())) {
57 RunImplOnCorrectThread(); 58 bool success = RunImplOnCorrectThread();
58 SendResponseOnUIThread(); 59 SendResponse(success);
59 } else { 60 } else {
60 content::BrowserThread::PostTaskAndReply( 61 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
61 rules_registry_->GetOwnerThread(), FROM_HERE, 62 content::BrowserThread::GetMessageLoopProxyForThread(
62 base::Bind(base::IgnoreResult(&RulesFunction::RunImplOnCorrectThread), 63 rules_registry_->GetOwnerThread());
63 this), 64 base::PostTaskAndReplyWithResult(
64 base::Bind(&RulesFunction::SendResponseOnUIThread, this)); 65 message_loop_proxy,
66 FROM_HERE,
67 base::Bind(&RulesFunction::RunImplOnCorrectThread, this),
68 base::Bind(&RulesFunction::SendResponse, this));
65 } 69 }
66 70
67 return true; 71 return true;
68 } 72 }
69 73
70 void RulesFunction::SendResponseOnUIThread() {
71 SendResponse(error_.empty());
72 }
73
74 bool AddRulesFunction::RunImplOnCorrectThread() { 74 bool AddRulesFunction::RunImplOnCorrectThread() {
75 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); 75 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_));
76 EXTENSION_FUNCTION_VALIDATE(params.get()); 76 EXTENSION_FUNCTION_VALIDATE(params.get());
77 77
78 error_ = rules_registry_->AddRules(extension_id(), params->rules); 78 error_ = rules_registry_->AddRules(extension_id(), params->rules);
79 79
80 if (error_.empty()) 80 if (error_.empty())
81 result_.reset(AddRules::Result::Create(params->rules)); 81 result_.reset(AddRules::Result::Create(params->rules));
82 82
83 return error_.empty(); 83 return error_.empty();
(...skipping 26 matching lines...) Expand all
110 error_ = rules_registry_->GetAllRules(extension_id(), &rules); 110 error_ = rules_registry_->GetAllRules(extension_id(), &rules);
111 } 111 }
112 112
113 if (error_.empty()) 113 if (error_.empty())
114 result_.reset(GetRules::Result::Create(rules)); 114 result_.reset(GetRules::Result::Create(rules));
115 115
116 return error_.empty(); 116 return error_.empty();
117 } 117 }
118 118
119 } // namespace extensions 119 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/declarative/declarative_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698