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

Side by Side Diff: chrome/service/cloud_print/job_status_updater.cc

Issue 4165013: Re-landing issue 4202006 (http://codereview.chromium.org/4202006/show) which ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/service/cloud_print/job_status_updater.h" 5 #include "chrome/service/cloud_print/job_status_updater.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/common/net/http_return.h" 10 #include "chrome/common/net/http_return.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } else { 51 } else {
52 // If GetJobDetails failed, the most likely case is that the job no 52 // If GetJobDetails failed, the most likely case is that the job no
53 // longer exists in the OS queue. We are going to assume it is done in 53 // longer exists in the OS queue. We are going to assume it is done in
54 // this case. 54 // this case.
55 last_job_details_.Clear(); 55 last_job_details_.Clear();
56 last_job_details_.status = cloud_print::PRINT_JOB_STATUS_COMPLETED; 56 last_job_details_.status = cloud_print::PRINT_JOB_STATUS_COMPLETED;
57 need_update = true; 57 need_update = true;
58 } 58 }
59 } 59 }
60 if (need_update) { 60 if (need_update) {
61 GURL update_url = CloudPrintHelpers::GetUrlForJobStatusUpdate( 61 request_ = new CloudPrintURLFetcher;
62 cloud_print_server_url_, job_id_, last_job_details_); 62 request_->StartGetRequest(
63 request_.reset(new URLFetcher(update_url, URLFetcher::GET, this)); 63 CloudPrintHelpers::GetUrlForJobStatusUpdate(
64 CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_); 64 cloud_print_server_url_, job_id_, last_job_details_),
65 request_->Start(); 65 this, auth_token_, kCloudPrintAPIRetryPolicy);
66 } 66 }
67 } 67 }
68 } 68 }
69 69
70 void JobStatusUpdater::Stop() { 70 void JobStatusUpdater::Stop() {
71 request_.reset(); 71 request_ = NULL;
72 DCHECK(delegate_); 72 DCHECK(delegate_);
73 stopped_ = true; 73 stopped_ = true;
74 delegate_->OnJobCompleted(this); 74 delegate_->OnJobCompleted(this);
75 } 75 }
76 76
77 // URLFetcher::Delegate implementation. 77 // CloudPrintURLFetcher::Delegate implementation.
78 void JobStatusUpdater::OnURLFetchComplete(const URLFetcher* source, 78 CloudPrintURLFetcher::ResponseAction JobStatusUpdater::HandleJSONData(
79 const GURL& url, 79 const URLFetcher* source,
80 const URLRequestStatus& status, 80 const GURL& url,
81 int response_code, 81 DictionaryValue* json_data,
82 const ResponseCookies& cookies, 82 bool succeeded) {
83 const std::string& data) { 83 if (last_job_details_.status == cloud_print::PRINT_JOB_STATUS_COMPLETED) {
84 // If there was an auth error, we are done.
85 if (RC_FORBIDDEN == response_code) {
86 if (delegate_) {
87 delegate_->OnAuthError();
88 }
89 return;
90 }
91 int64 next_update_interval = kJobStatusUpdateInterval;
92 if (!status.is_success() || (response_code != 200)) {
93 next_update_interval *= 10;
94 MessageLoop::current()->PostDelayedTask(
95 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::UpdateStatus),
96 next_update_interval);
97 } else if (last_job_details_.status ==
98 cloud_print::PRINT_JOB_STATUS_COMPLETED) {
99 MessageLoop::current()->PostTask( 84 MessageLoop::current()->PostTask(
100 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::Stop)); 85 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::Stop));
101 } 86 }
87 return CloudPrintURLFetcher::STOP_PROCESSING;
102 } 88 }
89
90 void JobStatusUpdater::OnRequestAuthError() {
91 if (delegate_)
92 delegate_->OnAuthError();
93 }
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/job_status_updater.h ('k') | chrome/service/cloud_print/printer_job_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698