1 // Copyright 2013 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. 4 5 #ifndef MOJO_SHELL_LOADER_H_ 6 #define MOJO_SHELL_LOADER_H_ 7 8 #include "base/files/file_path.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/single_thread_task_runner.h" 11 #include "base/threading/thread.h" 12 #include "mojo/shell/url_request_context_getter.h" 13 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher_delegate.h" 15 #include "url/gurl.h" 16 17 namespace net { 18 class NetworkDelegate; 19 } 20 21 namespace mojo { 22 namespace shell { 23 24 class Loader { 25 public: 26 class Delegate { 27 public: 28 virtual void DidCompleteLoad(const GURL& app_url, 29 const base::FilePath& app_path) = 0; 30 31 protected: 32 virtual ~Delegate(); 33 }; 34 35 class Job : public net::URLFetcherDelegate { 36 public: 37 // You can cancel a job by deleting it. 38 virtual ~Job(); 39 40 private: 41 friend class Loader; 42 43 // You can create a job using Loader::Load. 44 Job(const GURL& app_url, Delegate* delegate); 45 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 46 47 scoped_ptr<net::URLFetcher> fetcher_; 48 Delegate* delegate_; 49 50 DISALLOW_COPY_AND_ASSIGN(Job); 51 }; 52 53 Loader(base::SingleThreadTaskRunner* network_runner, 54 base::SingleThreadTaskRunner* file_runner, 55 base::MessageLoopProxy* cache_runner, 56 scoped_ptr<net::NetworkDelegate> network_delegate, 57 base::FilePath base_path); 58 ~Loader(); 59 60 scoped_ptr<Job> Load(const GURL& app_url, Delegate* delegate); 61 62 private: 63 scoped_refptr<base::SingleThreadTaskRunner> file_runner_; 64 scoped_refptr<URLRequestContextGetter> url_request_context_getter_; 65 66 DISALLOW_COPY_AND_ASSIGN(Loader); 67 }; 68 69 } // namespace shell 70 } // namespace mojo 71 72 #endif // MOJO_SHELL_LOADER_H_ 73