summaryrefslogtreecommitdiffstats
path: root/chrome/browser/apps/drive/drive_app_converter.h
blob: 515f9ef67005a38714e4efcdbaf5e706cba19335 (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 2014 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 CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_
#define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_

#include <string>

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "chrome/browser/drive/drive_app_registry.h"
#include "chrome/browser/extensions/install_observer.h"
#include "chrome/common/web_application_info.h"

class Profile;

namespace extensions {
class CrxInstaller;
class Extension;
}

// DriveAppConverter creates and installs a local URL app for the given
// DriveAppInfo into the given profile.
class DriveAppConverter : public extensions::InstallObserver {
 public:
  typedef base::Callback<void(const DriveAppConverter*, bool success)>
      FinishedCallback;

  DriveAppConverter(Profile* profile,
                    const drive::DriveAppInfo& drive_app_info,
                    const FinishedCallback& finished_callback);
  ~DriveAppConverter() override;

  void Start();
  bool IsStarted() const;

  bool IsInstalling(const std::string& app_id) const;

  const drive::DriveAppInfo& drive_app_info() const { return drive_app_info_; }
  const extensions::Extension* extension() const { return extension_; }
  bool is_new_install() const { return is_new_install_; }

 private:
  class IconFetcher;

  // Callbacks from IconFetcher.
  void OnIconFetchComplete(const IconFetcher* fetcher);

  void StartInstall();
  void PostInstallCleanUp();

  // extensions::InstallObserver:
  void OnFinishCrxInstall(const std::string& extension_id,
                          bool success) override;

  Profile* profile_;
  const drive::DriveAppInfo drive_app_info_;

  WebApplicationInfo web_app_;
  const extensions::Extension* extension_;
  bool is_new_install_;

  ScopedVector<IconFetcher> fetchers_;
  scoped_refptr<extensions::CrxInstaller> crx_installer_;

  FinishedCallback finished_callback_;

  DISALLOW_COPY_AND_ASSIGN(DriveAppConverter);
};

#endif  // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_