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

Side by Side Diff: chrome/browser/rlz/rlz_extension_api.cc

Issue 9699054: rlz: Hook up on mac, switch to chrome's network stack on win. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/rlz/rlz_extension_api.h" 5 #include "chrome/browser/rlz/rlz_extension_api.h"
6 6
7 #include "base/bind.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/threading/sequenced_worker_pool.h"
8 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
9 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
11 #include "rlz/lib/lib_values.h" 14 #include "rlz/lib/lib_values.h"
15 #include "rlz/lib/rlz_lib.h"
12 16
13 namespace { 17 namespace {
14 18
15 bool GetProductFromName(const std::string& product_name, 19 bool GetProductFromName(const std::string& product_name,
16 rlz_lib::Product* product) { 20 rlz_lib::Product* product) {
17 bool success = true; 21 bool success = true;
18 switch (product_name[0]) { 22 switch (product_name[0]) {
19 case 'B': 23 case 'B':
20 *product = rlz_lib::FF_TOOLBAR; 24 *product = rlz_lib::FF_TOOLBAR;
21 break; 25 break;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 rlz_lib::AccessPoint access_point; 110 rlz_lib::AccessPoint access_point;
107 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName(ap_name.c_str(), 111 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName(ap_name.c_str(),
108 &access_point)); 112 &access_point));
109 113
110 char rlz[rlz_lib::kMaxRlzLength + 1]; 114 char rlz[rlz_lib::kMaxRlzLength + 1];
111 rlz_lib::GetAccessPointRlz(access_point, rlz, rlz_lib::kMaxRlzLength); 115 rlz_lib::GetAccessPointRlz(access_point, rlz, rlz_lib::kMaxRlzLength);
112 result_.reset(Value::CreateStringValue(rlz)); 116 result_.reset(Value::CreateStringValue(rlz));
113 return true; 117 return true;
114 } 118 }
115 119
120 RlzSendFinancialPingFunction::RlzSendFinancialPingFunction() {
121 }
122
123 RlzSendFinancialPingFunction::~RlzSendFinancialPingFunction() {
124 }
125
116 bool RlzSendFinancialPingFunction::RunImpl() { 126 bool RlzSendFinancialPingFunction::RunImpl() {
117 // This can be slow if registry access goes to disk. Should preferably
118 // perform registry operations on the File thread.
119 // http://code.google.com/p/chromium/issues/detail?id=62098
120 base::ThreadRestrictions::ScopedAllowIO allow_io;
121
122 std::string product_name; 127 std::string product_name;
123 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name)); 128 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name));
124 rlz_lib::Product product; 129 EXTENSION_FUNCTION_VALIDATE(GetProductFromName(product_name, &product_));
125 EXTENSION_FUNCTION_VALIDATE(GetProductFromName(product_name, &product));
126 130
127 ListValue* access_points_list; 131 ListValue* access_points_list;
128 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &access_points_list)); 132 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &access_points_list));
129 if (access_points_list->GetSize() < 1) { 133 if (access_points_list->GetSize() < 1) {
130 EXTENSION_FUNCTION_ERROR("Access point array should not be empty."); 134 EXTENSION_FUNCTION_ERROR("Access point array should not be empty.");
131 } 135 }
132 136
133 // Allocate an access point array to pass to ClearProductState(). The array 137 // Allocate an access point array to pass to ClearProductState(). The array
134 // must be termindated with the value rlz_lib::NO_ACCESS_POINT, hence + 1 138 // must be terminated with the value rlz_lib::NO_ACCESS_POINT, hence + 1
135 // when allocating the array. 139 // when allocating the array.
136 scoped_array<rlz_lib::AccessPoint> access_points( 140 access_points_.reset(
137 new rlz_lib::AccessPoint[access_points_list->GetSize() + 1]); 141 new rlz_lib::AccessPoint[access_points_list->GetSize() + 1]);
138 142
139 size_t i; 143 size_t i;
140 for (i = 0; i < access_points_list->GetSize(); ++i) { 144 for (i = 0; i < access_points_list->GetSize(); ++i) {
141 std::string ap_name; 145 std::string ap_name;
142 EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name)); 146 EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name));
143 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName( 147 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName(
144 ap_name.c_str(), &access_points[i])); 148 ap_name.c_str(), &access_points_[i]));
145 } 149 }
146 access_points[i] = rlz_lib::NO_ACCESS_POINT; 150 access_points_[i] = rlz_lib::NO_ACCESS_POINT;
147 151
148 std::string signature; 152 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &signature_));
149 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &signature)); 153 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &brand_));
154 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &id_));
155 EXTENSION_FUNCTION_VALIDATE(args_->GetString(5, &lang_));
156 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(6, &exclude_machine_id_));
150 157
151 std::string brand; 158 // |system_request_context| needs to run on the UI thread.
152 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &brand)); 159 rlz_lib::SetURLRequestContext(g_browser_process->system_request_context());
153 160
154 std::string id; 161 content::BrowserThread::GetBlockingPool()->PostTask(
155 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &id)); 162 FROM_HERE,
163 base::Bind(&RlzSendFinancialPingFunction::WorkOnWorkerThread, this));
156 164
157 std::string lang; 165 return true;
158 EXTENSION_FUNCTION_VALIDATE(args_->GetString(5, &lang)); 166 }
159 167
160 bool exclude_machine_id; 168 void RlzSendFinancialPingFunction::WorkOnWorkerThread() {
161 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(6, &exclude_machine_id));
162
163 // rlz_lib::SendFinancialPing() will not send a ping more often than once in 169 // rlz_lib::SendFinancialPing() will not send a ping more often than once in
164 // any 24-hour period. Calling it more often has no effect. If a ping is 170 // any 24-hour period. Calling it more often has no effect. If a ping is
165 // not sent false is returned, but this is not an error, so we should not 171 // not sent false is returned, but this is not an error, so we should not
166 // use the return value of rlz_lib::SendFinancialPing() as the return value 172 // use the return value of rlz_lib::SendFinancialPing() as the return value
167 // of this function. Callers interested in the return value can register 173 // of this function. Callers interested in the return value can register
168 // an optional callback function. 174 // an optional callback function.
169 bool sent = rlz_lib::SendFinancialPing(product, access_points.get(), 175 bool sent = rlz_lib::SendFinancialPing(product_, access_points_.get(),
170 signature.c_str(), brand.c_str(), 176 signature_.c_str(), brand_.c_str(),
171 id.c_str(), lang.c_str(), 177 id_.c_str(), lang_.c_str(),
172 exclude_machine_id); 178 exclude_machine_id_);
179
173 result_.reset(Value::CreateBooleanValue(sent)); 180 result_.reset(Value::CreateBooleanValue(sent));
174 return true; 181
182 bool post_task_result = content::BrowserThread::PostTask(
183 content::BrowserThread::UI, FROM_HERE,
184 base::Bind(&RlzSendFinancialPingFunction::RespondOnUIThread, this));
185 DCHECK(post_task_result);
186 }
187
188 void RlzSendFinancialPingFunction::RespondOnUIThread() {
189 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
190 SendResponse(true);
175 } 191 }
176 192
177 bool RlzClearProductStateFunction::RunImpl() { 193 bool RlzClearProductStateFunction::RunImpl() {
178 // This can be slow if registry access goes to disk. Should preferably 194 // This can be slow if registry access goes to disk. Should preferably
179 // perform registry operations on the File thread. 195 // perform registry operations on the File thread.
180 // http://code.google.com/p/chromium/issues/detail?id=62098 196 // http://code.google.com/p/chromium/issues/detail?id=62098
181 base::ThreadRestrictions::ScopedAllowIO allow_io; 197 base::ThreadRestrictions::ScopedAllowIO allow_io;
182 198
183 std::string product_name; 199 std::string product_name;
184 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name)); 200 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name));
(...skipping 17 matching lines...) Expand all
202 std::string ap_name; 218 std::string ap_name;
203 EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name)); 219 EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name));
204 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName( 220 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName(
205 ap_name.c_str(), &access_points[i])); 221 ap_name.c_str(), &access_points[i]));
206 } 222 }
207 access_points[i] = rlz_lib::NO_ACCESS_POINT; 223 access_points[i] = rlz_lib::NO_ACCESS_POINT;
208 224
209 rlz_lib::ClearProductState(product, access_points.get()); 225 rlz_lib::ClearProductState(product, access_points.get());
210 return true; 226 return true;
211 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698