Home | History | Annotate | Download | only in push_messaging
      1 // Copyright (c) 2012 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_EXTENSIONS_API_PUSH_MESSAGING_SYNC_SETUP_HELPER_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_SYNC_SETUP_HELPER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "net/dns/mock_host_resolver.h"
     14 
     15 class Profile;
     16 class ProfileSyncServiceHarness;
     17 
     18 namespace extensions {
     19 
     20 class SyncSetupHelper {
     21  public:
     22   SyncSetupHelper();
     23 
     24   ~SyncSetupHelper();
     25 
     26   // Performs one-time initialization to enable sync for a profile. Does nothing
     27   // if sync is already enabled for the profile.
     28   bool InitializeSync(Profile* profile);
     29 
     30   // Helper method used to read GAIA credentials from a local password file.
     31   // Note: The password file must be a plain text file with two lines.
     32   // The username is on the first line and the password is on the second line.
     33   bool ReadPasswordFile(const base::FilePath& passwordFile);
     34 
     35   const std::string& client_id() const { return client_id_; }
     36   const std::string& client_secret() const { return client_secret_; }
     37   const std::string& refresh_token() const { return refresh_token_; }
     38 
     39  private:
     40   // Block until all sync clients have completed their mutual sync cycles.
     41   // Return true if a quiescent state was successfully reached.
     42   bool AwaitQuiescence();
     43 
     44   // GAIA account used by the test case.
     45   std::string username_;
     46 
     47   // GAIA password used by the test case.
     48   std::string password_;
     49 
     50   // GAIA client id for making the API call to push messaging.
     51   std::string client_id_;
     52 
     53   // GAIA client secret for making the API call to push messaging.
     54   std::string client_secret_;
     55 
     56   // GAIA refresh token for making the API call to push messaging.
     57   std::string refresh_token_;
     58 
     59   // The sync profile used by a test. The profile is owned by the
     60   // ProfileManager.
     61   Profile* profile_;
     62 
     63   // Sync client used by a test. A sync client is associated with
     64   // a sync profile, and implements methods that sync the contents of the
     65   // profile with the server.
     66   scoped_ptr<ProfileSyncServiceHarness> client_;
     67 
     68   // This test needs to make live DNS requests for access to
     69   // GAIA and sync server URLs under google.com. We use a scoped version
     70   // to override the default resolver while the test is active.
     71   scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_;
     72 
     73   DISALLOW_COPY_AND_ASSIGN(SyncSetupHelper);
     74 };
     75 
     76 }  // namespace extensions
     77 
     78 #endif  // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_SYNC_SETUP_HELPER_H_
     79