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

Side by Side Diff: chrome/browser/pepper_flash_settings_manager.cc

Issue 10986059: Fail incoming requests in PepperFlashSettingsManager after an error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix? Created 8 years, 2 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/pepper_flash_settings_manager.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/pepper_flash_settings_manager.h" 5 #include "chrome/browser/pepper_flash_settings_manager.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 #include "ppapi/proxy/ppapi_messages.h" 26 #include "ppapi/proxy/ppapi_messages.h"
27 #include "webkit/plugins/plugin_constants.h" 27 #include "webkit/plugins/plugin_constants.h"
28 #include "webkit/plugins/webplugininfo.h" 28 #include "webkit/plugins/webplugininfo.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 class PepperFlashSettingsManager::Core 32 class PepperFlashSettingsManager::Core
33 : public IPC::Listener, 33 : public IPC::Listener,
34 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> { 34 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> {
35 public: 35 public:
36 Core(PepperFlashSettingsManager* manager, 36 Core(base::WeakPtr<PepperFlashSettingsManager> manager,
37 content::BrowserContext* browser_context); 37 content::BrowserContext* browser_context);
38 38
39 void Initialize(); 39 void Initialize();
40 // Stops sending notifications to |manager_| and sets it to NULL. 40 // Stops sending notifications to |manager_|.
41 void Detach(); 41 void Detach();
42 42
43 void DeauthorizeContentLicenses(uint32 request_id); 43 void DeauthorizeContentLicenses(uint32 request_id);
44 void GetPermissionSettings( 44 void GetPermissionSettings(
45 uint32 request_id, 45 uint32 request_id,
46 PP_Flash_BrowserOperations_SettingType setting_type); 46 PP_Flash_BrowserOperations_SettingType setting_type);
47 void SetDefaultPermission( 47 void SetDefaultPermission(
48 uint32 request_id, 48 uint32 request_id,
49 PP_Flash_BrowserOperations_SettingType setting_type, 49 PP_Flash_BrowserOperations_SettingType setting_type,
50 PP_Flash_BrowserOperations_Permission permission, 50 PP_Flash_BrowserOperations_Permission permission,
(...skipping 18 matching lines...) Expand all
69 enum RequestType { 69 enum RequestType {
70 INVALID_REQUEST_TYPE = 0, 70 INVALID_REQUEST_TYPE = 0,
71 DEAUTHORIZE_CONTENT_LICENSES, 71 DEAUTHORIZE_CONTENT_LICENSES,
72 GET_PERMISSION_SETTINGS, 72 GET_PERMISSION_SETTINGS,
73 SET_DEFAULT_PERMISSION, 73 SET_DEFAULT_PERMISSION,
74 SET_SITE_PERMISSION, 74 SET_SITE_PERMISSION,
75 GET_SITES_WITH_DATA, 75 GET_SITES_WITH_DATA,
76 CLEAR_SITE_DATA, 76 CLEAR_SITE_DATA,
77 }; 77 };
78 78
79 enum State {
80 STATE_UNINITIALIZED = 0,
81 STATE_INITIALIZED,
82 STATE_ERROR,
83 STATE_DETACHED,
84 };
85
79 struct PendingRequest { 86 struct PendingRequest {
80 PendingRequest() 87 PendingRequest()
81 : id(0), 88 : id(0),
82 type(INVALID_REQUEST_TYPE), 89 type(INVALID_REQUEST_TYPE),
83 setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC), 90 setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC),
84 permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT), 91 permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT),
85 clear_site_specific(false), 92 clear_site_specific(false),
86 flags(0), 93 flags(0),
87 max_age(0) { 94 max_age(0) {
88 } 95 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bool success, 164 bool success,
158 PP_Flash_BrowserOperations_Permission default_permission, 165 PP_Flash_BrowserOperations_Permission default_permission,
159 const ppapi::FlashSiteSettings& sites); 166 const ppapi::FlashSiteSettings& sites);
160 void OnSetDefaultPermissionResult(uint32 request_id, bool success); 167 void OnSetDefaultPermissionResult(uint32 request_id, bool success);
161 void OnSetSitePermissionResult(uint32 request_id, bool success); 168 void OnSetSitePermissionResult(uint32 request_id, bool success);
162 void OnGetSitesWithDataResult(uint32 request_id, 169 void OnGetSitesWithDataResult(uint32 request_id,
163 const std::vector<std::string>& sites); 170 const std::vector<std::string>& sites);
164 void OnClearSiteDataResult(uint32 request_id, bool success); 171 void OnClearSiteDataResult(uint32 request_id, bool success);
165 172
166 // Used only on the UI thread. 173 // Used only on the UI thread.
167 PepperFlashSettingsManager* manager_; 174 base::WeakPtr<PepperFlashSettingsManager> manager_;
168 175
169 // Used only on the I/O thread. 176 // Used only on the I/O thread.
170 FilePath plugin_data_path_; 177 FilePath plugin_data_path_;
171 178
172 // The channel is NULL until we have opened a connection to the broker 179 // The channel is NULL until we have opened a connection to the broker
173 // process. Used only on the I/O thread. 180 // process. Used only on the I/O thread.
174 scoped_ptr<IPC::Channel> channel_; 181 scoped_ptr<IPC::Channel> channel_;
175 182
176 // Used only on the I/O thread. 183 // Used only on the I/O thread.
177 bool initialized_; 184 State state_;
178 // Whether Detach() has been called on the UI thread. When it is true, further
179 // work is not necessary. Used only on the I/O thread.
180 bool detached_;
181 185
182 // Requests that need to be sent once the channel to the broker process is 186 // Requests that need to be sent once the channel to the broker process is
183 // established. Used only on the I/O thread. 187 // established. Used only on the I/O thread.
184 std::vector<PendingRequest> pending_requests_; 188 std::vector<PendingRequest> pending_requests_;
185 // Requests that have been sent but haven't got replied. Used only on the 189 // Requests that have been sent but haven't got replied. Used only on the
186 // I/O thread. 190 // I/O thread.
187 std::map<uint32, RequestType> pending_responses_; 191 std::map<uint32, RequestType> pending_responses_;
188 192
189 // Used only on the I/O thread. 193 // Used only on the I/O thread.
190 scoped_refptr<content::PepperFlashSettingsHelper> helper_; 194 scoped_refptr<content::PepperFlashSettingsHelper> helper_;
191 195
192 // Path for the current profile. Must be retrieved on the UI thread from the 196 // Path for the current profile. Must be retrieved on the UI thread from the
193 // browser context when we start so we can use it later on the I/O thread. 197 // browser context when we start so we can use it later on the I/O thread.
194 FilePath browser_context_path_; 198 FilePath browser_context_path_;
195 199
196 scoped_refptr<PluginPrefs> plugin_prefs_; 200 scoped_refptr<PluginPrefs> plugin_prefs_;
197 }; 201 };
198 202
199 PepperFlashSettingsManager::Core::Core(PepperFlashSettingsManager* manager, 203 PepperFlashSettingsManager::Core::Core(
200 content::BrowserContext* browser_context) 204 base::WeakPtr<PepperFlashSettingsManager> manager,
205 content::BrowserContext* browser_context)
201 : manager_(manager), 206 : manager_(manager),
202 initialized_(false), 207 state_(STATE_UNINITIALIZED),
203 detached_(false),
204 browser_context_path_(browser_context->GetPath()), 208 browser_context_path_(browser_context->GetPath()),
205 plugin_prefs_(PluginPrefs::GetForProfile( 209 plugin_prefs_(PluginPrefs::GetForProfile(
206 Profile::FromBrowserContext(browser_context))) { 210 Profile::FromBrowserContext(browser_context))) {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
208 } 212 }
209 213
210 PepperFlashSettingsManager::Core::~Core() { 214 PepperFlashSettingsManager::Core::~Core() {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
212 } 216 }
213 217
214 void PepperFlashSettingsManager::Core::Initialize() { 218 void PepperFlashSettingsManager::Core::Initialize() {
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
216 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 220 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
217 base::Bind(&Core::InitializeOnIOThread, this)); 221 base::Bind(&Core::InitializeOnIOThread, this));
218 } 222 }
219 223
220 void PepperFlashSettingsManager::Core::Detach() { 224 void PepperFlashSettingsManager::Core::Detach() {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
222 226
223 manager_ = NULL; 227 // This call guarantees that one ref is retained until we get to the DETACHED
224 // This call guarantees that one ref is retained until |detached_| is set to 228 // state. This is important. Otherwise, if the ref count drops to zero on the
225 // true. This is important. Otherwise, if the ref count drops to zero on the
226 // UI thread (which posts a task to delete this object on the I/O thread) 229 // UI thread (which posts a task to delete this object on the I/O thread)
227 // while the I/O thread doesn't know about it, methods on the I/O thread might 230 // while the I/O thread doesn't know about it, methods on the I/O thread might
228 // increase the ref count again and cause double deletion. 231 // increase the ref count again and cause double deletion.
229 BrowserThread::PostTask( 232 BrowserThread::PostTask(
230 BrowserThread::IO, FROM_HERE, base::Bind(&Core::DetachOnIOThread, this)); 233 BrowserThread::IO, FROM_HERE, base::Bind(&Core::DetachOnIOThread, this));
231 } 234 }
232 235
233 void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses( 236 void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
234 uint32 request_id) { 237 uint32 request_id) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult, 315 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult,
313 OnClearSiteDataResult) 316 OnClearSiteDataResult)
314 IPC_MESSAGE_UNHANDLED_ERROR() 317 IPC_MESSAGE_UNHANDLED_ERROR()
315 IPC_END_MESSAGE_MAP() 318 IPC_END_MESSAGE_MAP()
316 319
317 return true; 320 return true;
318 } 321 }
319 322
320 void PepperFlashSettingsManager::Core::OnChannelError() { 323 void PepperFlashSettingsManager::Core::OnChannelError() {
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
322 if (detached_) 325 if (state_ == STATE_DETACHED)
323 return; 326 return;
324 327
325 NotifyErrorFromIOThread(); 328 NotifyErrorFromIOThread();
326 } 329 }
327 330
328 void PepperFlashSettingsManager::Core::ConnectToChannel( 331 void PepperFlashSettingsManager::Core::ConnectToChannel(
329 bool success, 332 bool success,
330 const IPC::ChannelHandle& handle) { 333 const IPC::ChannelHandle& handle) {
331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
332 if (detached_) 335 if (state_ == STATE_DETACHED)
333 return; 336 return;
334 337
335 DCHECK(!initialized_); 338 DCHECK(state_ == STATE_UNINITIALIZED);
336 DCHECK(!channel_.get()); 339 DCHECK(!channel_.get());
337 340
338 if (!success) { 341 if (!success) {
339 DLOG(ERROR) << "Couldn't open plugin channel"; 342 DLOG(ERROR) << "Couldn't open plugin channel";
340 NotifyErrorFromIOThread(); 343 NotifyErrorFromIOThread();
341 return; 344 return;
342 } 345 }
343 346
344 channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this)); 347 channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this));
345 if (!channel_->Connect()) { 348 if (!channel_->Connect()) {
346 DLOG(ERROR) << "Couldn't connect to plugin"; 349 DLOG(ERROR) << "Couldn't connect to plugin";
347 NotifyErrorFromIOThread(); 350 NotifyErrorFromIOThread();
348 return; 351 return;
349 } 352 }
350 353
351 initialized_ = true; 354 state_ = STATE_INITIALIZED;
352 355
353 std::vector<PendingRequest> temp_pending_requests; 356 std::vector<PendingRequest> temp_pending_requests;
354 temp_pending_requests.swap(pending_requests_); 357 temp_pending_requests.swap(pending_requests_);
355 for (std::vector<PendingRequest>::iterator iter = 358 for (std::vector<PendingRequest>::iterator iter =
356 temp_pending_requests.begin(); 359 temp_pending_requests.begin();
357 iter != temp_pending_requests.end(); ++iter) { 360 iter != temp_pending_requests.end(); ++iter) {
358 switch (iter->type) { 361 switch (iter->type) {
359 case INVALID_REQUEST_TYPE: 362 case INVALID_REQUEST_TYPE:
360 NOTREACHED(); 363 NOTREACHED();
361 break; 364 break;
(...skipping 17 matching lines...) Expand all
379 case CLEAR_SITE_DATA: 382 case CLEAR_SITE_DATA:
380 ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags, 383 ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags,
381 iter->max_age); 384 iter->max_age);
382 break; 385 break;
383 } 386 }
384 } 387 }
385 } 388 }
386 389
387 void PepperFlashSettingsManager::Core::InitializeOnIOThread() { 390 void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
389 DCHECK(!initialized_); 392 DCHECK_EQ(STATE_UNINITIALIZED, state_);
yzshen1 2012/09/30 18:19:15 Create Core -> Detach() -> Initialize() will get u
Bernhard Bauer 2012/10/01 18:34:27 Right, that what I intended the DCHECK for ;-) I
390
391 if (detached_)
392 return;
393 393
394 webkit::WebPluginInfo plugin_info; 394 webkit::WebPluginInfo plugin_info;
395 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(), 395 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
396 &plugin_info)) { 396 &plugin_info)) {
397 NotifyErrorFromIOThread(); 397 NotifyErrorFromIOThread();
398 return; 398 return;
399 } 399 }
400 400
401 FilePath profile_path = 401 FilePath profile_path =
402 browser_context_path_.Append(content::kPepperDataDirname); 402 browser_context_path_.Append(content::kPepperDataDirname);
403 #if defined(OS_WIN) 403 #if defined(OS_WIN)
404 plugin_data_path_ = profile_path.Append(plugin_info.name); 404 plugin_data_path_ = profile_path.Append(plugin_info.name);
405 #else 405 #else
406 plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name)); 406 plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name));
407 #endif 407 #endif
408 408
409 helper_ = content::PepperFlashSettingsHelper::Create(); 409 helper_ = content::PepperFlashSettingsHelper::Create();
410 content::PepperFlashSettingsHelper::OpenChannelCallback callback = 410 content::PepperFlashSettingsHelper::OpenChannelCallback callback =
411 base::Bind(&Core::ConnectToChannel, this); 411 base::Bind(&Core::ConnectToChannel, this);
412 helper_->OpenChannelToBroker(plugin_info.path, callback); 412 helper_->OpenChannelToBroker(plugin_info.path, callback);
413 } 413 }
414 414
415 void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread( 415 void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
416 uint32 request_id) { 416 uint32 request_id) {
417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
418 if (detached_) 418 DCHECK_NE(STATE_DETACHED, state_);
419 return;
420 419
421 if (!initialized_) { 420 if (state_ == STATE_UNINITIALIZED) {
422 PendingRequest request; 421 PendingRequest request;
423 request.id = request_id; 422 request.id = request_id;
424 request.type = DEAUTHORIZE_CONTENT_LICENSES; 423 request.type = DEAUTHORIZE_CONTENT_LICENSES;
425 pending_requests_.push_back(request); 424 pending_requests_.push_back(request);
426 return; 425 return;
427 } 426 }
428 427
429 pending_responses_.insert( 428 pending_responses_.insert(
430 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES)); 429 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
430 if (state_ == STATE_ERROR) {
431 NotifyErrorFromIOThread();
yzshen1 2012/09/30 18:19:15 The problem of calling NotifyErrorFromIOThread a s
Bernhard Bauer 2012/10/01 18:34:27 Oh, you're right! I went with 1 (otherwise we'd n
432 return;
433 }
434
431 IPC::Message* msg = 435 IPC::Message* msg =
432 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_); 436 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
433 if (!channel_->Send(msg)) { 437 if (!channel_->Send(msg)) {
434 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message"; 438 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
435 // A failure notification for the current request will be sent since 439 // A failure notification for the current request will be sent since
436 // |pending_responses_| has been updated. 440 // |pending_responses_| has been updated.
437 NotifyErrorFromIOThread(); 441 NotifyErrorFromIOThread();
438 } 442 }
439 } 443 }
440 444
441 void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread( 445 void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
442 uint32 request_id, 446 uint32 request_id,
443 PP_Flash_BrowserOperations_SettingType setting_type) { 447 PP_Flash_BrowserOperations_SettingType setting_type) {
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
445 if (detached_) 449 DCHECK_NE(STATE_DETACHED, state_);
446 return;
447 450
448 if (!initialized_) { 451 if (state_ == STATE_UNINITIALIZED) {
449 PendingRequest request; 452 PendingRequest request;
450 request.id = request_id; 453 request.id = request_id;
451 request.type = GET_PERMISSION_SETTINGS; 454 request.type = GET_PERMISSION_SETTINGS;
452 request.setting_type = setting_type; 455 request.setting_type = setting_type;
453 pending_requests_.push_back(request); 456 pending_requests_.push_back(request);
454 return; 457 return;
455 } 458 }
456 459
457 pending_responses_.insert( 460 pending_responses_.insert(
458 std::make_pair(request_id, GET_PERMISSION_SETTINGS)); 461 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
462 if (state_ == STATE_ERROR) {
463 NotifyErrorFromIOThread();
464 return;
465 }
466
459 IPC::Message* msg = new PpapiMsg_GetPermissionSettings( 467 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
460 request_id, plugin_data_path_, setting_type); 468 request_id, plugin_data_path_, setting_type);
461 if (!channel_->Send(msg)) { 469 if (!channel_->Send(msg)) {
462 DLOG(ERROR) << "Couldn't send GetPermissionSettings message"; 470 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
463 // A failure notification for the current request will be sent since 471 // A failure notification for the current request will be sent since
464 // |pending_responses_| has been updated. 472 // |pending_responses_| has been updated.
465 NotifyErrorFromIOThread(); 473 NotifyErrorFromIOThread();
466 } 474 }
467 } 475 }
468 476
469 void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread( 477 void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
470 uint32 request_id, 478 uint32 request_id,
471 PP_Flash_BrowserOperations_SettingType setting_type, 479 PP_Flash_BrowserOperations_SettingType setting_type,
472 PP_Flash_BrowserOperations_Permission permission, 480 PP_Flash_BrowserOperations_Permission permission,
473 bool clear_site_specific) { 481 bool clear_site_specific) {
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
475 if (detached_) 483 DCHECK_NE(STATE_DETACHED, state_);
476 return;
477 484
478 if (!initialized_) { 485 if (state_ == STATE_UNINITIALIZED) {
479 PendingRequest request; 486 PendingRequest request;
480 request.id = request_id; 487 request.id = request_id;
481 request.type = SET_DEFAULT_PERMISSION; 488 request.type = SET_DEFAULT_PERMISSION;
482 request.setting_type = setting_type; 489 request.setting_type = setting_type;
483 request.permission = permission; 490 request.permission = permission;
484 request.clear_site_specific = clear_site_specific; 491 request.clear_site_specific = clear_site_specific;
485 pending_requests_.push_back(request); 492 pending_requests_.push_back(request);
486 return; 493 return;
487 } 494 }
488 495
489 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION)); 496 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
497 if (state_ == STATE_ERROR) {
498 NotifyErrorFromIOThread();
499 return;
500 }
501
490 IPC::Message* msg = new PpapiMsg_SetDefaultPermission( 502 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
491 request_id, plugin_data_path_, setting_type, permission, 503 request_id, plugin_data_path_, setting_type, permission,
492 clear_site_specific); 504 clear_site_specific);
493 if (!channel_->Send(msg)) { 505 if (!channel_->Send(msg)) {
494 DLOG(ERROR) << "Couldn't send SetDefaultPermission message"; 506 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
495 // A failure notification for the current request will be sent since 507 // A failure notification for the current request will be sent since
496 // |pending_responses_| has been updated. 508 // |pending_responses_| has been updated.
497 NotifyErrorFromIOThread(); 509 NotifyErrorFromIOThread();
498 } 510 }
499 } 511 }
500 512
501 void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread( 513 void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
502 uint32 request_id, 514 uint32 request_id,
503 PP_Flash_BrowserOperations_SettingType setting_type, 515 PP_Flash_BrowserOperations_SettingType setting_type,
504 const ppapi::FlashSiteSettings& sites) { 516 const ppapi::FlashSiteSettings& sites) {
505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
506 if (detached_) 518 DCHECK_NE(STATE_DETACHED, state_);
507 return;
508 519
509 if (!initialized_) { 520 if (state_ == STATE_UNINITIALIZED) {
510 pending_requests_.push_back(PendingRequest()); 521 pending_requests_.push_back(PendingRequest());
511 PendingRequest& request = pending_requests_.back(); 522 PendingRequest& request = pending_requests_.back();
512 request.id = request_id; 523 request.id = request_id;
513 request.type = SET_SITE_PERMISSION; 524 request.type = SET_SITE_PERMISSION;
514 request.setting_type = setting_type; 525 request.setting_type = setting_type;
515 request.sites = sites; 526 request.sites = sites;
516 return; 527 return;
517 } 528 }
518 529
519 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION)); 530 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
531 if (state_ == STATE_ERROR) {
532 NotifyErrorFromIOThread();
533 return;
534 }
535
520 IPC::Message* msg = new PpapiMsg_SetSitePermission( 536 IPC::Message* msg = new PpapiMsg_SetSitePermission(
521 request_id, plugin_data_path_, setting_type, sites); 537 request_id, plugin_data_path_, setting_type, sites);
522 if (!channel_->Send(msg)) { 538 if (!channel_->Send(msg)) {
523 DLOG(ERROR) << "Couldn't send SetSitePermission message"; 539 DLOG(ERROR) << "Couldn't send SetSitePermission message";
524 // A failure notification for the current request will be sent since 540 // A failure notification for the current request will be sent since
525 // |pending_responses_| has been updated. 541 // |pending_responses_| has been updated.
526 NotifyErrorFromIOThread(); 542 NotifyErrorFromIOThread();
527 } 543 }
528 } 544 }
529 545
530 void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread( 546 void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
531 uint32 request_id) { 547 uint32 request_id) {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
533 if (detached_) 549 DCHECK_NE(STATE_DETACHED, state_);
534 return;
535 550
536 if (!initialized_) { 551 if (state_ == STATE_UNINITIALIZED) {
537 pending_requests_.push_back(PendingRequest()); 552 pending_requests_.push_back(PendingRequest());
538 PendingRequest& request = pending_requests_.back(); 553 PendingRequest& request = pending_requests_.back();
539 request.id = request_id; 554 request.id = request_id;
540 request.type = GET_SITES_WITH_DATA; 555 request.type = GET_SITES_WITH_DATA;
541 return; 556 return;
542 } 557 }
543 558
544 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA)); 559 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA));
560 if (state_ == STATE_ERROR) {
561 NotifyErrorFromIOThread();
562 return;
563 }
564
545 IPC::Message* msg = new PpapiMsg_GetSitesWithData( 565 IPC::Message* msg = new PpapiMsg_GetSitesWithData(
546 request_id, plugin_data_path_); 566 request_id, plugin_data_path_);
547 if (!channel_->Send(msg)) { 567 if (!channel_->Send(msg)) {
548 DLOG(ERROR) << "Couldn't send GetSitesWithData message"; 568 DLOG(ERROR) << "Couldn't send GetSitesWithData message";
549 // A failure notification for the current request will be sent since 569 // A failure notification for the current request will be sent since
550 // |pending_responses_| has been updated. 570 // |pending_responses_| has been updated.
551 NotifyErrorFromIOThread(); 571 NotifyErrorFromIOThread();
552 } 572 }
553 } 573 }
554 574
555 void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread( 575 void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
556 uint32 request_id, 576 uint32 request_id,
557 const std::string& site, 577 const std::string& site,
558 uint64 flags, 578 uint64 flags,
559 uint64 max_age) { 579 uint64 max_age) {
560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
561 if (detached_) 581 DCHECK_NE(STATE_DETACHED, state_);
562 return;
563 582
564 if (!initialized_) { 583 if (state_ == STATE_UNINITIALIZED) {
565 pending_requests_.push_back(PendingRequest()); 584 pending_requests_.push_back(PendingRequest());
566 PendingRequest& request = pending_requests_.back(); 585 PendingRequest& request = pending_requests_.back();
567 request.id = request_id; 586 request.id = request_id;
568 request.type = CLEAR_SITE_DATA; 587 request.type = CLEAR_SITE_DATA;
569 request.site = site; 588 request.site = site;
570 request.flags = flags; 589 request.flags = flags;
571 request.max_age = max_age; 590 request.max_age = max_age;
572 return; 591 return;
573 } 592 }
574 593
575 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA)); 594 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA));
595 if (state_ == STATE_ERROR) {
596 NotifyErrorFromIOThread();
597 return;
598 }
599
576 IPC::Message* msg = new PpapiMsg_ClearSiteData( 600 IPC::Message* msg = new PpapiMsg_ClearSiteData(
577 request_id, plugin_data_path_, site, flags, max_age); 601 request_id, plugin_data_path_, site, flags, max_age);
578 if (!channel_->Send(msg)) { 602 if (!channel_->Send(msg)) {
579 DLOG(ERROR) << "Couldn't send ClearSiteData message"; 603 DLOG(ERROR) << "Couldn't send ClearSiteData message";
580 // A failure notification for the current request will be sent since 604 // A failure notification for the current request will be sent since
581 // |pending_responses_| has been updated. 605 // |pending_responses_| has been updated.
582 NotifyErrorFromIOThread(); 606 NotifyErrorFromIOThread();
583 } 607 }
584 } 608 }
585 609
586 void PepperFlashSettingsManager::Core::DetachOnIOThread() { 610 void PepperFlashSettingsManager::Core::DetachOnIOThread() {
587 detached_ = true; 611 state_ = STATE_DETACHED;
588 } 612 }
589 613
590 void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() { 614 void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
592 if (detached_) 616 if (state_ == STATE_DETACHED)
593 return; 617 return;
594 618
619 state_ = STATE_ERROR;
595 std::vector<std::pair<uint32, RequestType> > notifications; 620 std::vector<std::pair<uint32, RequestType> > notifications;
596 for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin(); 621 for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin();
597 iter != pending_requests_.end(); ++iter) { 622 iter != pending_requests_.end(); ++iter) {
598 notifications.push_back(std::make_pair(iter->id, iter->type)); 623 notifications.push_back(std::make_pair(iter->id, iter->type));
599 } 624 }
600 pending_requests_.clear(); 625 pending_requests_.clear();
601 notifications.insert(notifications.end(), pending_responses_.begin(), 626 notifications.insert(notifications.end(), pending_responses_.begin(),
602 pending_responses_.end()); 627 pending_responses_.end());
603 pending_responses_.clear(); 628 pending_responses_.clear();
604 629
605 BrowserThread::PostTask( 630 BrowserThread::PostTask(
606 BrowserThread::UI, FROM_HERE, 631 BrowserThread::UI, FROM_HERE,
607 base::Bind(&Core::NotifyError, this, notifications)); 632 base::Bind(&Core::NotifyError, this, notifications));
608 } 633 }
609 634
610 void 635 void
611 PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted( 636 PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted(
612 uint32 request_id, 637 uint32 request_id,
613 bool success) { 638 bool success) {
614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
615 640
616 if (manager_) { 641 if (manager_.get()) {
617 manager_->client_->OnDeauthorizeContentLicensesCompleted( 642 manager_->client_->OnDeauthorizeContentLicensesCompleted(
618 request_id, success); 643 request_id, success);
619 } 644 }
620 } 645 }
621 646
622 void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted( 647 void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
623 uint32 request_id, 648 uint32 request_id,
624 bool success, 649 bool success,
625 PP_Flash_BrowserOperations_Permission default_permission, 650 PP_Flash_BrowserOperations_Permission default_permission,
626 const ppapi::FlashSiteSettings& sites) { 651 const ppapi::FlashSiteSettings& sites) {
627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
628 653
629 if (manager_) { 654 if (manager_.get()) {
630 manager_->client_->OnGetPermissionSettingsCompleted( 655 manager_->client_->OnGetPermissionSettingsCompleted(
631 request_id, success, default_permission, sites); 656 request_id, success, default_permission, sites);
632 } 657 }
633 } 658 }
634 659
635 void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted( 660 void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
636 uint32 request_id, 661 uint32 request_id,
637 bool success) { 662 bool success) {
638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
639 664
640 if (manager_) { 665 if (manager_.get()) {
641 manager_->client_->OnSetDefaultPermissionCompleted( 666 manager_->client_->OnSetDefaultPermissionCompleted(
642 request_id, success); 667 request_id, success);
643 } 668 }
644 } 669 }
645 670
646 void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted( 671 void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
647 uint32 request_id, 672 uint32 request_id,
648 bool success) { 673 bool success) {
649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
650 675
651 if (manager_) { 676 if (manager_.get()) {
652 manager_->client_->OnSetSitePermissionCompleted( 677 manager_->client_->OnSetSitePermissionCompleted(
653 request_id, success); 678 request_id, success);
654 } 679 }
655 } 680 }
656 681
657 void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted( 682 void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
658 uint32 request_id, 683 uint32 request_id,
659 const std::vector<std::string>& sites) { 684 const std::vector<std::string>& sites) {
660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
661 686
662 if (manager_) { 687 if (manager_.get()) {
663 manager_->client_->OnGetSitesWithDataCompleted( 688 manager_->client_->OnGetSitesWithDataCompleted(
664 request_id, sites); 689 request_id, sites);
665 } 690 }
666 } 691 }
667 692
668 void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted( 693 void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
669 uint32 request_id, 694 uint32 request_id,
670 bool success) { 695 bool success) {
671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
672 697
673 if (manager_) 698 if (manager_.get())
674 manager_->client_->OnClearSiteDataCompleted(request_id, success); 699 manager_->client_->OnClearSiteDataCompleted(request_id, success);
675 } 700 }
676 701
677 void PepperFlashSettingsManager::Core::NotifyError( 702 void PepperFlashSettingsManager::Core::NotifyError(
678 const std::vector<std::pair<uint32, RequestType> >& notifications) { 703 const std::vector<std::pair<uint32, RequestType> >& notifications) {
679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 704 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
680 705
681 scoped_refptr<Core> protector(this); 706 scoped_refptr<Core> protector(this);
682 for (std::vector<std::pair<uint32, RequestType> >::const_iterator iter = 707 for (std::vector<std::pair<uint32, RequestType> >::const_iterator iter =
683 notifications.begin(); iter != notifications.end(); ++iter) { 708 notifications.begin(); iter != notifications.end(); ++iter) {
684 // Check |manager_| for each iteration in case Detach() happens in one of 709 // Check |manager_| for each iteration in case it is destroyed in one of
685 // the callbacks. 710 // the callbacks.
686 if (!manager_) 711 if (!manager_.get())
687 return; 712 return;
688 713
689 switch (iter->second) { 714 switch (iter->second) {
690 case INVALID_REQUEST_TYPE: 715 case INVALID_REQUEST_TYPE:
691 NOTREACHED(); 716 NOTREACHED();
692 break; 717 break;
693 case DEAUTHORIZE_CONTENT_LICENSES: 718 case DEAUTHORIZE_CONTENT_LICENSES:
694 manager_->client_->OnDeauthorizeContentLicensesCompleted( 719 manager_->client_->OnDeauthorizeContentLicensesCompleted(
695 iter->first, false); 720 iter->first, false);
696 break; 721 break;
(...skipping 12 matching lines...) Expand all
709 case GET_SITES_WITH_DATA: 734 case GET_SITES_WITH_DATA:
710 manager_->client_->OnGetSitesWithDataCompleted( 735 manager_->client_->OnGetSitesWithDataCompleted(
711 iter->first, std::vector<std::string>()); 736 iter->first, std::vector<std::string>());
712 break; 737 break;
713 case CLEAR_SITE_DATA: 738 case CLEAR_SITE_DATA:
714 manager_->client_->OnClearSiteDataCompleted(iter->first, false); 739 manager_->client_->OnClearSiteDataCompleted(iter->first, false);
715 break; 740 break;
716 } 741 }
717 } 742 }
718 743
719 if (manager_) 744 if (manager_.get())
720 manager_->OnError(); 745 manager_->OnError();
721 } 746 }
722 747
723 void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult( 748 void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
724 uint32 request_id, 749 uint32 request_id,
725 bool success) { 750 bool success) {
726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 751 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
727 if (detached_) 752 if (state_ == STATE_DETACHED)
728 return; 753 return;
729 754
730 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error"; 755 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
731 756
732 std::map<uint32, RequestType>::iterator iter = 757 std::map<uint32, RequestType>::iterator iter =
733 pending_responses_.find(request_id); 758 pending_responses_.find(request_id);
734 if (iter == pending_responses_.end()) 759 if (iter == pending_responses_.end())
735 return; 760 return;
736 761
737 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES); 762 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
738 763
739 pending_responses_.erase(iter); 764 pending_responses_.erase(iter);
740 BrowserThread::PostTask( 765 BrowserThread::PostTask(
741 BrowserThread::UI, FROM_HERE, 766 BrowserThread::UI, FROM_HERE,
742 base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted, this, 767 base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
743 request_id, success)); 768 request_id, success));
744 } 769 }
745 770
746 void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult( 771 void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
747 uint32 request_id, 772 uint32 request_id,
748 bool success, 773 bool success,
749 PP_Flash_BrowserOperations_Permission default_permission, 774 PP_Flash_BrowserOperations_Permission default_permission,
750 const ppapi::FlashSiteSettings& sites) { 775 const ppapi::FlashSiteSettings& sites) {
751 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
752 if (detached_) 777 if (state_ == STATE_DETACHED)
753 return; 778 return;
754 779
755 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error"; 780 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
756 781
757 std::map<uint32, RequestType>::iterator iter = 782 std::map<uint32, RequestType>::iterator iter =
758 pending_responses_.find(request_id); 783 pending_responses_.find(request_id);
759 if (iter == pending_responses_.end()) 784 if (iter == pending_responses_.end())
760 return; 785 return;
761 786
762 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS); 787 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
763 788
764 pending_responses_.erase(iter); 789 pending_responses_.erase(iter);
765 BrowserThread::PostTask( 790 BrowserThread::PostTask(
766 BrowserThread::UI, FROM_HERE, 791 BrowserThread::UI, FROM_HERE,
767 base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this, 792 base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this,
768 request_id, success, default_permission, sites)); 793 request_id, success, default_permission, sites));
769 } 794 }
770 795
771 void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult( 796 void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
772 uint32 request_id, 797 uint32 request_id,
773 bool success) { 798 bool success) {
774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 799 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
775 if (detached_) 800 if (state_ == STATE_DETACHED)
776 return; 801 return;
777 802
778 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error"; 803 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
779 804
780 std::map<uint32, RequestType>::iterator iter = 805 std::map<uint32, RequestType>::iterator iter =
781 pending_responses_.find(request_id); 806 pending_responses_.find(request_id);
782 if (iter == pending_responses_.end()) 807 if (iter == pending_responses_.end())
783 return; 808 return;
784 809
785 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION); 810 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
786 811
787 pending_responses_.erase(iter); 812 pending_responses_.erase(iter);
788 BrowserThread::PostTask( 813 BrowserThread::PostTask(
789 BrowserThread::UI, FROM_HERE, 814 BrowserThread::UI, FROM_HERE,
790 base::Bind(&Core::NotifySetDefaultPermissionCompleted, this, 815 base::Bind(&Core::NotifySetDefaultPermissionCompleted, this,
791 request_id, success)); 816 request_id, success));
792 } 817 }
793 818
794 void PepperFlashSettingsManager::Core::OnSetSitePermissionResult( 819 void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
795 uint32 request_id, 820 uint32 request_id,
796 bool success) { 821 bool success) {
797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
798 if (detached_) 823 if (state_ == STATE_DETACHED)
799 return; 824 return;
800 825
801 DLOG_IF(ERROR, !success) << "SetSitePermission returned error"; 826 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
802 827
803 std::map<uint32, RequestType>::iterator iter = 828 std::map<uint32, RequestType>::iterator iter =
804 pending_responses_.find(request_id); 829 pending_responses_.find(request_id);
805 if (iter == pending_responses_.end()) 830 if (iter == pending_responses_.end())
806 return; 831 return;
807 832
808 DCHECK_EQ(iter->second, SET_SITE_PERMISSION); 833 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
809 834
810 pending_responses_.erase(iter); 835 pending_responses_.erase(iter);
811 BrowserThread::PostTask( 836 BrowserThread::PostTask(
812 BrowserThread::UI, FROM_HERE, 837 BrowserThread::UI, FROM_HERE,
813 base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id, 838 base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id,
814 success)); 839 success));
815 } 840 }
816 841
817 void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult( 842 void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
818 uint32 request_id, 843 uint32 request_id,
819 const std::vector<std::string>& sites) { 844 const std::vector<std::string>& sites) {
820 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
821 if (detached_) 846 if (state_ == STATE_DETACHED)
822 return; 847 return;
823 848
824 std::map<uint32, RequestType>::iterator iter = 849 std::map<uint32, RequestType>::iterator iter =
825 pending_responses_.find(request_id); 850 pending_responses_.find(request_id);
826 if (iter == pending_responses_.end()) 851 if (iter == pending_responses_.end())
827 return; 852 return;
828 853
829 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA); 854 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
830 855
831 pending_responses_.erase(iter); 856 pending_responses_.erase(iter);
832 BrowserThread::PostTask( 857 BrowserThread::PostTask(
833 BrowserThread::UI, FROM_HERE, 858 BrowserThread::UI, FROM_HERE,
834 base::Bind(&Core::NotifyGetSitesWithDataCompleted, this, request_id, 859 base::Bind(&Core::NotifyGetSitesWithDataCompleted, this, request_id,
835 sites)); 860 sites));
836 } 861 }
837 862
838 void PepperFlashSettingsManager::Core::OnClearSiteDataResult( 863 void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
839 uint32 request_id, 864 uint32 request_id,
840 bool success) { 865 bool success) {
841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
842 if (detached_) 867 if (state_ == STATE_DETACHED)
843 return; 868 return;
844 869
845 DLOG_IF(ERROR, !success) << "ClearSiteData returned error"; 870 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
846 871
847 std::map<uint32, RequestType>::iterator iter = 872 std::map<uint32, RequestType>::iterator iter =
848 pending_responses_.find(request_id); 873 pending_responses_.find(request_id);
849 if (iter == pending_responses_.end()) 874 if (iter == pending_responses_.end())
850 return; 875 return;
851 876
852 DCHECK_EQ(iter->second, CLEAR_SITE_DATA); 877 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
853 878
854 pending_responses_.erase(iter); 879 pending_responses_.erase(iter);
855 BrowserThread::PostTask( 880 BrowserThread::PostTask(
856 BrowserThread::UI, FROM_HERE, 881 BrowserThread::UI, FROM_HERE,
857 base::Bind(&Core::NotifyClearSiteDataCompleted, this, request_id, 882 base::Bind(&Core::NotifyClearSiteDataCompleted, this, request_id,
858 success)); 883 success));
859 } 884 }
860 885
861 PepperFlashSettingsManager::PepperFlashSettingsManager( 886 PepperFlashSettingsManager::PepperFlashSettingsManager(
862 Client* client, 887 Client* client,
863 content::BrowserContext* browser_context) 888 content::BrowserContext* browser_context)
864 : client_(client), 889 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
890 client_(client),
865 browser_context_(browser_context), 891 browser_context_(browser_context),
866 next_request_id_(1) { 892 next_request_id_(1) {
867 DCHECK(client); 893 DCHECK(client);
868 DCHECK(browser_context); 894 DCHECK(browser_context);
869 } 895 }
870 896
871 PepperFlashSettingsManager::~PepperFlashSettingsManager() { 897 PepperFlashSettingsManager::~PepperFlashSettingsManager() {
872 if (core_.get()) 898 if (core_.get())
873 core_->Detach(); 899 core_->Detach();
874 } 900 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 core_->ClearSiteData(id, site, flags, max_age); 996 core_->ClearSiteData(id, site, flags, max_age);
971 return id; 997 return id;
972 } 998 }
973 999
974 uint32 PepperFlashSettingsManager::GetNextRequestId() { 1000 uint32 PepperFlashSettingsManager::GetNextRequestId() {
975 return next_request_id_++; 1001 return next_request_id_++;
976 } 1002 }
977 1003
978 void PepperFlashSettingsManager::EnsureCoreExists() { 1004 void PepperFlashSettingsManager::EnsureCoreExists() {
979 if (!core_.get()) { 1005 if (!core_.get()) {
980 core_ = new Core(this, browser_context_); 1006 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
981 core_->Initialize(); 1007 core_->Initialize();
982 } 1008 }
983 } 1009 }
984 1010
985 void PepperFlashSettingsManager::OnError() { 1011 void PepperFlashSettingsManager::OnError() {
986 if (core_.get()) { 1012 if (!core_.get())
987 core_->Detach(); 1013 return;
988 core_ = NULL; 1014
989 } else { 1015 core_->Detach();
990 NOTREACHED(); 1016 core_ = NULL;
991 }
992 } 1017 }
993
OLDNEW
« no previous file with comments | « chrome/browser/pepper_flash_settings_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698