OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utilit
y_client.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utilit
y_client.h" |
9 #include "chrome/common/chrome_utility_messages.h" | 9 #include "chrome/common/chrome_utility_messages.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 | 11 |
12 using content::BrowserThread; | 12 using content::BrowserThread; |
13 | 13 |
14 ImageWriterUtilityClient::ImageWriterUtilityClient() | 14 ImageWriterUtilityClient::ImageWriterUtilityClient() |
15 : message_loop_proxy_(base::MessageLoopProxy::current()) {} | 15 : message_loop_proxy_(base::MessageLoopProxy::current()) {} |
16 ImageWriterUtilityClient::~ImageWriterUtilityClient() {} | 16 ImageWriterUtilityClient::~ImageWriterUtilityClient() {} |
17 | 17 |
18 void ImageWriterUtilityClient::Write(const ProgressCallback& progress_callback, | 18 void ImageWriterUtilityClient::Write(const ProgressCallback& progress_callback, |
19 const SuccessCallback& success_callback, | 19 const SuccessCallback& success_callback, |
20 const ErrorCallback& error_callback, | 20 const ErrorCallback& error_callback, |
21 const base::FilePath& source, | 21 const base::FilePath& source, |
22 const base::FilePath& target) { | 22 const base::FilePath& target) { |
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 23 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
24 | 24 |
25 StartHost(); | 25 StartHost(); |
26 | 26 |
27 progress_callback_ = progress_callback; | 27 progress_callback_ = progress_callback; |
28 success_callback_ = success_callback; | 28 success_callback_ = success_callback; |
29 error_callback_ = error_callback; | 29 error_callback_ = error_callback; |
30 | 30 |
31 if (!Send(new ChromeUtilityMsg_ImageWriter_Write(source, target))) { | 31 if (!Send(new ChromeUtilityMsg_ImageWriter_Write(source, target))) { |
32 DLOG(ERROR) << "Unable to send Write message to Utility Process."; | 32 DLOG(ERROR) << "Unable to send Write message to Utility Process."; |
33 message_loop_proxy_->PostTask( | 33 message_loop_proxy_->PostTask( |
34 FROM_HERE, base::Bind(error_callback_, "IPC communication failed")); | 34 FROM_HERE, base::Bind(error_callback_, "IPC communication failed")); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 void ImageWriterUtilityClient::Verify(const ProgressCallback& progress_callback, | 38 void ImageWriterUtilityClient::Verify(const ProgressCallback& progress_callback, |
39 const SuccessCallback& success_callback, | 39 const SuccessCallback& success_callback, |
40 const ErrorCallback& error_callback, | 40 const ErrorCallback& error_callback, |
41 const base::FilePath& source, | 41 const base::FilePath& source, |
42 const base::FilePath& target) { | 42 const base::FilePath& target) { |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
44 | 44 |
45 StartHost(); | 45 StartHost(); |
46 | 46 |
47 progress_callback_ = progress_callback; | 47 progress_callback_ = progress_callback; |
48 success_callback_ = success_callback; | 48 success_callback_ = success_callback; |
49 error_callback_ = error_callback; | 49 error_callback_ = error_callback; |
50 | 50 |
51 if (!Send(new ChromeUtilityMsg_ImageWriter_Verify(source, target))) { | 51 if (!Send(new ChromeUtilityMsg_ImageWriter_Verify(source, target))) { |
52 DLOG(ERROR) << "Unable to send Verify message to Utility Process."; | 52 DLOG(ERROR) << "Unable to send Verify message to Utility Process."; |
53 message_loop_proxy_->PostTask( | 53 message_loop_proxy_->PostTask( |
54 FROM_HERE, base::Bind(error_callback_, "IPC communication failed")); | 54 FROM_HERE, base::Bind(error_callback_, "IPC communication failed")); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 void ImageWriterUtilityClient::Cancel(const CancelCallback& cancel_callback) { | 58 void ImageWriterUtilityClient::Cancel(const CancelCallback& cancel_callback) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
60 | 60 |
61 if (!utility_process_host_) { | 61 if (!utility_process_host_) { |
62 // If we haven't connected, there is nothing to cancel. | 62 // If we haven't connected, there is nothing to cancel. |
63 message_loop_proxy_->PostTask(FROM_HERE, cancel_callback); | 63 message_loop_proxy_->PostTask(FROM_HERE, cancel_callback); |
64 return; | 64 return; |
65 } | 65 } |
66 | 66 |
67 cancel_callback_ = cancel_callback; | 67 cancel_callback_ = cancel_callback; |
68 | 68 |
69 if (!Send(new ChromeUtilityMsg_ImageWriter_Cancel())) { | 69 if (!Send(new ChromeUtilityMsg_ImageWriter_Cancel())) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 base::Bind(error_callback_, message)); | 149 base::Bind(error_callback_, message)); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 void ImageWriterUtilityClient::OnWriteImageProgress(int64 progress) { | 153 void ImageWriterUtilityClient::OnWriteImageProgress(int64 progress) { |
154 if (!progress_callback_.is_null()) { | 154 if (!progress_callback_.is_null()) { |
155 message_loop_proxy_->PostTask(FROM_HERE, | 155 message_loop_proxy_->PostTask(FROM_HERE, |
156 base::Bind(progress_callback_, progress)); | 156 base::Bind(progress_callback_, progress)); |
157 } | 157 } |
158 } | 158 } |
OLD | NEW |