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

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: Merged with ToT 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
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/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" 10 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); 46 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name));
47 47
48 RulesRegistryService* rules_registry_service = 48 RulesRegistryService* rules_registry_service =
49 profile()->GetExtensionService()->GetRulesRegistryService(); 49 profile()->GetExtensionService()->GetRulesRegistryService();
50 rules_registry_ = rules_registry_service->GetRulesRegistry(event_name); 50 rules_registry_ = rules_registry_service->GetRulesRegistry(event_name);
51 // Raw access to this function is not available to extensions, therefore 51 // Raw access to this function is not available to extensions, therefore
52 // there should never be a request for a nonexisting rules registry. 52 // there should never be a request for a nonexisting rules registry.
53 EXTENSION_FUNCTION_VALIDATE(rules_registry_); 53 EXTENSION_FUNCTION_VALIDATE(rules_registry_);
54 54
55 if (content::BrowserThread::CurrentlyOn(rules_registry_->GetOwnerThread())) { 55 if (content::BrowserThread::CurrentlyOn(rules_registry_->GetOwnerThread())) {
56 RunImplOnCorrectThread(); 56 bool success = RunImplOnCorrectThread();
57 SendResponseOnUIThread(); 57 SendResponse(success);
58 } else { 58 } else {
59 content::BrowserThread::PostTaskAndReply( 59 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
60 rules_registry_->GetOwnerThread(), FROM_HERE, 60 content::BrowserThread::GetMessageLoopProxyForThread(
61 base::Bind(base::IgnoreResult(&RulesFunction::RunImplOnCorrectThread), 61 rules_registry_->GetOwnerThread());
62 this), 62 message_loop_proxy->PostTaskAndReplyWithResult(
63 base::Bind(&RulesFunction::SendResponseOnUIThread, this)); 63 FROM_HERE,
64 base::Bind(&RulesFunction::RunImplOnCorrectThread, this),
65 base::Bind(&RulesFunction::SendResponse, this));
64 } 66 }
65 67
66 return true; 68 return true;
67 } 69 }
68 70
69 void RulesFunction::SendResponseOnUIThread() {
70 SendResponse(error_.empty());
71 }
72
73 bool AddRulesFunction::RunImplOnCorrectThread() { 71 bool AddRulesFunction::RunImplOnCorrectThread() {
74 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); 72 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_));
75 EXTENSION_FUNCTION_VALIDATE(params.get()); 73 EXTENSION_FUNCTION_VALIDATE(params.get());
76 74
77 error_ = rules_registry_->AddRules(extension_id(), params->rules); 75 error_ = rules_registry_->AddRules(extension_id(), params->rules);
78 76
79 if (error_.empty()) 77 if (error_.empty())
80 result_.reset(AddRules::Result::Create(params->rules)); 78 result_.reset(AddRules::Result::Create(params->rules));
81 79
82 return error_.empty(); 80 return error_.empty();
(...skipping 26 matching lines...) Expand all
109 error_ = rules_registry_->GetAllRules(extension_id(), &rules); 107 error_ = rules_registry_->GetAllRules(extension_id(), &rules);
110 } 108 }
111 109
112 if (error_.empty()) 110 if (error_.empty())
113 result_.reset(GetRules::Result::Create(rules)); 111 result_.reset(GetRules::Result::Create(rules));
114 112
115 return error_.empty(); 113 return error_.empty();
116 } 114 }
117 115
118 } // namespace extensions 116 } // namespace extensions
OLDNEW
« base/task_runner.h ('K') | « 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