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 MOJO_TOOLS_PACKAGE_MANAGER_FETCHER_H_
6 #define MOJO_TOOLS_PACKAGE_MANAGER_FETCHER_H_
8 #include "base/files/file.h"
9 #include "base/files/file_path.h"
10 #include "mojo/common/handle_watcher.h"
11 #include "mojo/public/cpp/system/macros.h"
12 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
13 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
22 class PackageFetcherDelegate;
24 class PackageFetcher {
26 PackageFetcher(NetworkService* network_service,
27 PackageFetcherDelegate* delegate,
29 virtual ~PackageFetcher();
32 void OnReceivedResponse(URLResponsePtr response);
34 void ReadData(MojoResult);
35 void WaitToReadMore();
37 PackageFetcherDelegate* delegate_;
39 // URL of the package.
44 // Valid once file has started streaming.
45 ScopedDataPipeConsumerHandle body_;
46 common::HandleWatcher handle_watcher_;
48 base::FilePath output_file_name_;
49 base::File output_file_;
51 MOJO_DISALLOW_COPY_AND_ASSIGN(PackageFetcher);
54 class PackageFetcherDelegate {
56 virtual void FetchSucceeded(const GURL& url, const base::FilePath& name) = 0;
58 virtual void FetchFailed(const GURL& url) = 0;
63 #endif // MOJO_TOOLS_PACKAGE_MANAGER_FETCHER_H_