• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_
6 #define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_
7 
8 #include <string>
9 
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_vector.h"
14 #include "chrome/browser/drive/drive_app_registry.h"
15 #include "chrome/browser/extensions/install_observer.h"
16 #include "chrome/common/web_application_info.h"
17 
18 class Profile;
19 
20 namespace extensions {
21 class CrxInstaller;
22 class Extension;
23 }
24 
25 // DriveAppConverter creates and installs a local URL app for the given
26 // DriveAppInfo into the given profile.
27 class DriveAppConverter : public extensions::InstallObserver {
28  public:
29   typedef base::Callback<void(const DriveAppConverter*, bool success)>
30       FinishedCallback;
31 
32   DriveAppConverter(Profile* profile,
33                     const drive::DriveAppInfo& drive_app_info,
34                     const FinishedCallback& finished_callback);
35   virtual ~DriveAppConverter();
36 
37   void Start();
38   bool IsStarted() const;
39 
40   bool IsInstalling(const std::string& app_id) const;
41 
drive_app_info()42   const drive::DriveAppInfo& drive_app_info() const { return drive_app_info_; }
extension()43   const extensions::Extension* extension() const { return extension_; }
is_new_install()44   bool is_new_install() const { return is_new_install_; }
45 
46  private:
47   class IconFetcher;
48 
49   // Callbacks from IconFetcher.
50   void OnIconFetchComplete(const IconFetcher* fetcher);
51 
52   void StartInstall();
53   void PostInstallCleanUp();
54 
55   // extensions::InstallObserver:
56   virtual void OnFinishCrxInstall(const std::string& extension_id,
57                                   bool success) OVERRIDE;
58 
59   Profile* profile_;
60   const drive::DriveAppInfo drive_app_info_;
61 
62   WebApplicationInfo web_app_;
63   const extensions::Extension* extension_;
64   bool is_new_install_;
65 
66   ScopedVector<IconFetcher> fetchers_;
67   scoped_refptr<extensions::CrxInstaller> crx_installer_;
68 
69   FinishedCallback finished_callback_;
70 
71   DISALLOW_COPY_AND_ASSIGN(DriveAppConverter);
72 };
73 
74 #endif  // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_
75