summaryrefslogtreecommitdiffstats
path: root/mojo/shell/loader.h
blob: 2279cbd5261864e5079c7159459534101b9032ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_SHELL_LOADER_H_
#define MOJO_SHELL_LOADER_H_

#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "mojo/shell/url_request_context_getter.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"

namespace net {
class NetworkDelegate;
}

namespace mojo {
namespace shell {

class Loader {
 public:
  class Delegate {
   public:
    // |mime_type| is NULL if a mime type was not specified.
    virtual void DidCompleteLoad(const GURL& app_url,
                                 const base::FilePath& app_path,
                                 const std::string* mime_type) = 0;

   protected:
    virtual ~Delegate();
  };

  class Job : public net::URLFetcherDelegate {
   public:
    // You can cancel a job by deleting it.
    virtual ~Job();

   private:
    friend class Loader;

    // You can create a job using Loader::Load.
    Job(const GURL& app_url, Delegate* delegate);
    virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;

    scoped_ptr<net::URLFetcher> fetcher_;
    Delegate* delegate_;

    DISALLOW_COPY_AND_ASSIGN(Job);
  };

  Loader(base::SingleThreadTaskRunner* network_runner,
         base::SingleThreadTaskRunner* file_runner,
         base::MessageLoopProxy* cache_runner,
         scoped_ptr<net::NetworkDelegate> network_delegate,
         base::FilePath base_path);
  ~Loader();

  scoped_ptr<Job> Load(const GURL& app_url, Delegate* delegate);

 private:
  scoped_refptr<base::SingleThreadTaskRunner> file_runner_;
  scoped_refptr<URLRequestContextGetter> url_request_context_getter_;

  DISALLOW_COPY_AND_ASSIGN(Loader);
};

}  // namespace shell
}  // namespace mojo

#endif  // MOJO_SHELL_LOADER_H_