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

Side by Side Diff: chrome/browser/policy/cloud/device_management_service.cc

Issue 25690003: Refactored the DeviceManagementService to get its parameters from a delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
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/policy/cloud/device_management_service.h" 5 #include "chrome/browser/policy/cloud/device_management_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 478
479 DeviceManagementService::~DeviceManagementService() { 479 DeviceManagementService::~DeviceManagementService() {
480 // All running jobs should have been cancelled by now. 480 // All running jobs should have been cancelled by now.
481 DCHECK(pending_jobs_.empty()); 481 DCHECK(pending_jobs_.empty());
482 DCHECK(queued_jobs_.empty()); 482 DCHECK(queued_jobs_.empty());
483 } 483 }
484 484
485 DeviceManagementRequestJob* DeviceManagementService::CreateJob( 485 DeviceManagementRequestJob* DeviceManagementService::CreateJob(
486 DeviceManagementRequestJob::JobType type) { 486 DeviceManagementRequestJob::JobType type) {
487 return new DeviceManagementRequestJobImpl( 487 return new DeviceManagementRequestJobImpl(
488 type, agent_parameter_, platform_parameter_, this); 488 type,
489 configuration_->GetAgentParameter(),
490 configuration_->GetPlatformParameter(),
491 this);
489 } 492 }
490 493
491 void DeviceManagementService::ScheduleInitialization(int64 delay_milliseconds) { 494 void DeviceManagementService::ScheduleInitialization(int64 delay_milliseconds) {
492 if (initialized_) 495 if (initialized_)
493 return; 496 return;
494 base::MessageLoop::current()->PostDelayedTask( 497 base::MessageLoop::current()->PostDelayedTask(
495 FROM_HERE, 498 FROM_HERE,
496 base::Bind(&DeviceManagementService::Initialize, 499 base::Bind(&DeviceManagementService::Initialize,
497 weak_ptr_factory_.GetWeakPtr()), 500 weak_ptr_factory_.GetWeakPtr()),
498 base::TimeDelta::FromMilliseconds(delay_milliseconds)); 501 base::TimeDelta::FromMilliseconds(delay_milliseconds));
499 } 502 }
500 503
501 void DeviceManagementService::Initialize() { 504 void DeviceManagementService::Initialize() {
502 if (initialized_) 505 if (initialized_)
503 return; 506 return;
504 DCHECK(!request_context_getter_.get()); 507 DCHECK(!request_context_getter_.get());
505 request_context_getter_ = 508 request_context_getter_ = new DeviceManagementRequestContextGetter(
506 new DeviceManagementRequestContextGetter(request_context_, user_agent_); 509 request_context_, configuration_->GetUserAgent());
507 initialized_ = true; 510 initialized_ = true;
508 511
509 while (!queued_jobs_.empty()) { 512 while (!queued_jobs_.empty()) {
510 StartJob(queued_jobs_.front()); 513 StartJob(queued_jobs_.front());
511 queued_jobs_.pop_front(); 514 queued_jobs_.pop_front();
512 } 515 }
513 } 516 }
514 517
515 void DeviceManagementService::Shutdown() { 518 void DeviceManagementService::Shutdown() {
516 for (JobFetcherMap::iterator job(pending_jobs_.begin()); 519 for (JobFetcherMap::iterator job(pending_jobs_.begin());
517 job != pending_jobs_.end(); 520 job != pending_jobs_.end();
518 ++job) { 521 ++job) {
519 delete job->first; 522 delete job->first;
520 queued_jobs_.push_back(job->second); 523 queued_jobs_.push_back(job->second);
521 } 524 }
522 pending_jobs_.clear(); 525 pending_jobs_.clear();
523 } 526 }
524 527
525 DeviceManagementService::DeviceManagementService( 528 DeviceManagementService::DeviceManagementService(
526 scoped_refptr<net::URLRequestContextGetter> request_context, 529 scoped_ptr<Configuration> configuration,
527 const std::string& server_url, 530 scoped_refptr<net::URLRequestContextGetter> request_context)
528 const std::string& user_agent, 531 : configuration_(configuration.Pass()),
529 const std::string& agent_parameter, 532 request_context_(request_context),
530 const std::string& platform_parameter)
531 : request_context_(request_context),
532 server_url_(server_url),
533 user_agent_(user_agent),
534 agent_parameter_(agent_parameter),
535 platform_parameter_(platform_parameter),
536 initialized_(false), 533 initialized_(false),
537 weak_ptr_factory_(this) { 534 weak_ptr_factory_(this) {}
pastarmovj 2013/10/02 11:14:10 I think it makes sense to have a DCHECK(configurat
Joao da Silva 2013/10/02 11:37:40 Done.
538 }
539 535
540 void DeviceManagementService::StartJob(DeviceManagementRequestJobImpl* job) { 536 void DeviceManagementService::StartJob(DeviceManagementRequestJobImpl* job) {
537 std::string server_url = configuration_->GetServerUrl();
541 net::URLFetcher* fetcher = net::URLFetcher::Create( 538 net::URLFetcher* fetcher = net::URLFetcher::Create(
542 kURLFetcherID, job->GetURL(server_url_), net::URLFetcher::POST, this); 539 kURLFetcherID, job->GetURL(server_url), net::URLFetcher::POST, this);
543 fetcher->SetRequestContext(request_context_getter_.get()); 540 fetcher->SetRequestContext(request_context_getter_.get());
544 job->ConfigureRequest(fetcher); 541 job->ConfigureRequest(fetcher);
545 pending_jobs_[fetcher] = job; 542 pending_jobs_[fetcher] = job;
546 fetcher->Start(); 543 fetcher->Start();
547 } 544 }
548 545
549 void DeviceManagementService::OnURLFetchComplete( 546 void DeviceManagementService::OnURLFetchComplete(
550 const net::URLFetcher* source) { 547 const net::URLFetcher* source) {
551 JobFetcherMap::iterator entry(pending_jobs_.find(source)); 548 JobFetcherMap::iterator entry(pending_jobs_.find(source));
552 if (entry == pending_jobs_.end()) { 549 if (entry == pending_jobs_.end()) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 585 }
589 } 586 }
590 587
591 const JobQueue::iterator elem = 588 const JobQueue::iterator elem =
592 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); 589 std::find(queued_jobs_.begin(), queued_jobs_.end(), job);
593 if (elem != queued_jobs_.end()) 590 if (elem != queued_jobs_.end())
594 queued_jobs_.erase(elem); 591 queued_jobs_.erase(elem);
595 } 592 }
596 593
597 } // namespace policy 594 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698