Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / image_writer_private / image_writer_utility_client.h
blob7af98d055ec71291a23e5b425b249f478034fa31
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/single_thread_task_runner.h"
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "content/public/browser/utility_process_host.h"
13 #include "content/public/browser/utility_process_host_client.h"
15 // Writes a disk image to a device inside the utility process.
16 class ImageWriterUtilityClient : public content::UtilityProcessHostClient {
17 public:
18 typedef base::Callback<void()> CancelCallback;
19 typedef base::Callback<void()> SuccessCallback;
20 typedef base::Callback<void(int64)> ProgressCallback;
21 typedef base::Callback<void(const std::string&)> ErrorCallback;
23 ImageWriterUtilityClient();
25 // Starts the write.
26 // |progress_callback|: Called periodically with the count of bytes processed.
27 // |success_callback|: Called at successful completion.
28 // |error_callback|: Called with an error message on failure.
29 // |source|: The path to the source file to read data from.
30 // |target|: The path to the target device to write the image file to.
31 virtual void Write(const ProgressCallback& progress_callback,
32 const SuccessCallback& success_callback,
33 const ErrorCallback& error_callback,
34 const base::FilePath& source,
35 const base::FilePath& target);
37 // Starts a verification.
38 // |progress_callback|: Called periodically with the count of bytes processed.
39 // |success_callback|: Called at successful completion.
40 // |error_callback|: Called with an error message on failure.
41 // |source|: The path to the source file to read data from.
42 // |target|: The path to the target device to write the image file to.
43 virtual void Verify(const ProgressCallback& progress_callback,
44 const SuccessCallback& success_callback,
45 const ErrorCallback& error_callback,
46 const base::FilePath& source,
47 const base::FilePath& target);
49 // Cancels any pending write or verification.
50 // |cancel_callback|: Called when the cancel has actually occurred.
51 virtual void Cancel(const CancelCallback& cancel_callback);
53 // Shuts down the Utility thread that may have been created.
54 virtual void Shutdown();
56 protected:
57 // It's a reference-counted object, so destructor is not public.
58 ~ImageWriterUtilityClient() override;
60 private:
61 // Ensures the UtilityProcessHost has been created.
62 void StartHost();
64 // UtilityProcessHostClient implementation.
65 void OnProcessCrashed(int exit_code) override;
66 void OnProcessLaunchFailed() override;
67 bool OnMessageReceived(const IPC::Message& message) override;
68 virtual bool Send(IPC::Message* msg);
70 // IPC message handlers.
71 void OnWriteImageSucceeded();
72 void OnWriteImageCancelled();
73 void OnWriteImageFailed(const std::string& message);
74 void OnWriteImageProgress(int64 progress);
76 CancelCallback cancel_callback_;
77 ProgressCallback progress_callback_;
78 SuccessCallback success_callback_;
79 ErrorCallback error_callback_;
81 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
85 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient);
88 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_CLIENT_H_