drive_first_run_controller.h revision f2477e01787aa58f445919b809d89e252beef54f
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#ifndef CHROME_BROWSER_CHROMEOS_FIRST_RUN_DRIVE_FIRST_RUN_CONTROLLER_H_ 5#define CHROME_BROWSER_CHROMEOS_FIRST_RUN_DRIVE_FIRST_RUN_CONTROLLER_H_ 6 7#include "base/basictypes.h" 8#include "base/observer_list.h" 9#include "base/timer/timer.h" 10#include "chrome/browser/profiles/profile.h" 11 12namespace chromeos { 13 14class DriveWebContentsManager; 15 16// This class is responsible for kicking off the Google Drive offline 17// initialization process. There is an initial delay to avoid contention when 18// the session starts. DriveFirstRunController will manage its own lifetime and 19// destroy itself when the initialization succeeds or fails. 20class DriveFirstRunController { 21 public: 22 class Observer { 23 public: 24 // Called when enabling offline mode times out. OnCompletion will be called 25 // immediately afterwards. 26 virtual void OnTimedOut() = 0; 27 28 // Called when the first run flow finishes, informing the observer of 29 // success or failure. 30 virtual void OnCompletion(bool success) = 0; 31 32 protected: 33 virtual ~Observer() {} 34 }; 35 36 DriveFirstRunController(); 37 ~DriveFirstRunController(); 38 39 // Starts the process to enable offline mode for the user's Drive account. 40 void EnableOfflineMode(); 41 42 // Manages observers of the first run flow. 43 void AddObserver(Observer* observer); 44 void RemoveObserver(Observer* observer); 45 46 // Set delay times for testing purposes. 47 void SetDelaysForTest(int initial_delay_secs, int timeout_secs); 48 49 // Set the app id and endpoint url for testing purposes. 50 void SetAppInfoForTest(const std::string& app_id, 51 const std::string& endpoint_url); 52 53 private: 54 // Used as a callback to indicate whether the offline initialization 55 // succeeds or fails. 56 void OnOfflineInit(bool success); 57 58 // Called when timed out waiting for offline initialization to complete. 59 void OnWebContentsTimedOut(); 60 61 // Cleans up internal state and schedules self for deletion. 62 void CleanUp(); 63 64 Profile* profile_; 65 scoped_ptr<DriveWebContentsManager> web_contents_manager_; 66 base::OneShotTimer<DriveFirstRunController> web_contents_timer_; 67 base::OneShotTimer<DriveFirstRunController> initial_delay_timer_; 68 bool started_; 69 ObserverList<Observer> observer_list_; 70 71 int initial_delay_secs_; 72 int web_contents_timeout_secs_; 73 std::string drive_offline_endpoint_url_; 74 std::string drive_hosted_app_id_; 75 76 DISALLOW_COPY_AND_ASSIGN(DriveFirstRunController); 77}; 78 79} // namespace chromeos 80 81#endif // CHROME_BROWSER_CHROMEOS_FIRST_RUN_DRIVE_FIRST_RUN_CONTROLLER_H_ 82