app_list: Re-enable people search.
[chromium-blink-merge.git] / chrome / browser / extensions / api / image_writer_private / image_writer_utility_client.h
blob5e2d9b55a2e16cd62a2f57e5496a6da2dfec2ebb
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_CLIENT_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_CLIENT_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/sequenced_worker_pool.h"
11 #include "content/public/browser/utility_process_host.h"
12 #include "content/public/browser/utility_process_host_client.h"
14 // Writes a disk image to a device inside the utility process.
15 class ImageWriterUtilityClient : public content::UtilityProcessHostClient {
16 public:
17 typedef base::Callback<void()> CancelCallback;
18 typedef base::Callback<void()> SuccessCallback;
19 typedef base::Callback<void(int64)> ProgressCallback;
20 typedef base::Callback<void(const std::string&)> ErrorCallback;
22 ImageWriterUtilityClient();
24 // Starts the write.
25 // |progress_callback|: Called periodically with the count of bytes processed.
26 // |success_callback|: Called at successful completion.
27 // |error_callback|: Called with an error message on failure.
28 // |source|: The path to the source file to read data from.
29 // |target|: The path to the target device to write the image file to.
30 virtual void Write(const ProgressCallback& progress_callback,
31 const SuccessCallback& success_callback,
32 const ErrorCallback& error_callback,
33 const base::FilePath& source,
34 const base::FilePath& target);
36 // Starts a verification.
37 // |progress_callback|: Called periodically with the count of bytes processed.
38 // |success_callback|: Called at successful completion.
39 // |error_callback|: Called with an error message on failure.
40 // |source|: The path to the source file to read data from.
41 // |target|: The path to the target device to write the image file to.
42 virtual void Verify(const ProgressCallback& progress_callback,
43 const SuccessCallback& success_callback,
44 const ErrorCallback& error_callback,
45 const base::FilePath& source,
46 const base::FilePath& target);
48 // Cancels any pending write or verification.
49 // |cancel_callback|: Called when the cancel has actually occurred.
50 virtual void Cancel(const CancelCallback& cancel_callback);
52 // Shuts down the Utility thread that may have been created.
53 virtual void Shutdown();
55 protected:
56 // It's a reference-counted object, so destructor is not public.
57 ~ImageWriterUtilityClient() override;
59 private:
60 // Ensures the UtilityProcessHost has been created.
61 void StartHost();
63 // UtilityProcessHostClient implementation.
64 void OnProcessCrashed(int exit_code) override;
65 void OnProcessLaunchFailed() override;
66 bool OnMessageReceived(const IPC::Message& message) override;
67 virtual bool Send(IPC::Message* msg);
69 // IPC message handlers.
70 void OnWriteImageSucceeded();
71 void OnWriteImageCancelled();
72 void OnWriteImageFailed(const std::string& message);
73 void OnWriteImageProgress(int64 progress);
75 CancelCallback cancel_callback_;
76 ProgressCallback progress_callback_;
77 SuccessCallback success_callback_;
78 ErrorCallback error_callback_;
80 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
82 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
84 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient);
87 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_CLIENT_H_