OLD | NEW |
---|---|
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 Loading... | |
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 content::BrowserThread::GetBlockingPool()->PostTask( |
152 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &brand)); | 159 FROM_HERE, |
160 base::Bind(&RlzSendFinancialPingFunction::WorkOnWorkerThread, this)); | |
161 return true; | |
162 } | |
153 | 163 |
154 std::string id; | 164 void RlzSendFinancialPingFunction::WorkOnWorkerThread() { |
155 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &id)); | 165 rlz_lib::SetURLRequestContext(g_browser_process->system_request_context()); |
Roger Tawa OOO till Jul 10th
2012/03/26 18:52:38
hmm, this does not look right. Its not reset at t
Nico
2012/03/26 20:26:57
It doesn't have to be reset. It just needs to be s
Roger Tawa OOO till Jul 10th
2012/03/26 21:06:53
OK.
| |
156 | |
157 std::string lang; | |
158 EXTENSION_FUNCTION_VALIDATE(args_->GetString(5, &lang)); | |
159 | |
160 bool exclude_machine_id; | |
161 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(6, &exclude_machine_id)); | |
162 | 166 |
163 // rlz_lib::SendFinancialPing() will not send a ping more often than once in | 167 // 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 | 168 // 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 | 169 // 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 | 170 // use the return value of rlz_lib::SendFinancialPing() as the return value |
167 // of this function. Callers interested in the return value can register | 171 // of this function. Callers interested in the return value can register |
168 // an optional callback function. | 172 // an optional callback function. |
169 bool sent = rlz_lib::SendFinancialPing(product, access_points.get(), | 173 bool sent = rlz_lib::SendFinancialPing(product_, access_points_.get(), |
170 signature.c_str(), brand.c_str(), | 174 signature_.c_str(), brand_.c_str(), |
171 id.c_str(), lang.c_str(), | 175 id_.c_str(), lang_.c_str(), |
172 exclude_machine_id); | 176 exclude_machine_id_); |
177 | |
173 result_.reset(Value::CreateBooleanValue(sent)); | 178 result_.reset(Value::CreateBooleanValue(sent)); |
174 return true; | 179 |
180 bool post_task_result = content::BrowserThread::PostTask( | |
181 content::BrowserThread::UI, FROM_HERE, | |
182 base::Bind(&RlzSendFinancialPingFunction::RespondOnUIThread, this)); | |
183 DCHECK(post_task_result); | |
184 } | |
185 | |
186 void RlzSendFinancialPingFunction::RespondOnUIThread() { | |
187 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
188 SendResponse(true); | |
175 } | 189 } |
176 | 190 |
177 bool RlzClearProductStateFunction::RunImpl() { | 191 bool RlzClearProductStateFunction::RunImpl() { |
178 // This can be slow if registry access goes to disk. Should preferably | 192 // This can be slow if registry access goes to disk. Should preferably |
179 // perform registry operations on the File thread. | 193 // perform registry operations on the File thread. |
180 // http://code.google.com/p/chromium/issues/detail?id=62098 | 194 // http://code.google.com/p/chromium/issues/detail?id=62098 |
181 base::ThreadRestrictions::ScopedAllowIO allow_io; | 195 base::ThreadRestrictions::ScopedAllowIO allow_io; |
182 | 196 |
183 std::string product_name; | 197 std::string product_name; |
184 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name)); | 198 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name)); |
(...skipping 17 matching lines...) Expand all Loading... | |
202 std::string ap_name; | 216 std::string ap_name; |
203 EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name)); | 217 EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name)); |
204 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName( | 218 EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName( |
205 ap_name.c_str(), &access_points[i])); | 219 ap_name.c_str(), &access_points[i])); |
206 } | 220 } |
207 access_points[i] = rlz_lib::NO_ACCESS_POINT; | 221 access_points[i] = rlz_lib::NO_ACCESS_POINT; |
208 | 222 |
209 rlz_lib::ClearProductState(product, access_points.get()); | 223 rlz_lib::ClearProductState(product, access_points.get()); |
210 return true; | 224 return true; |
211 } | 225 } |
OLD | NEW |