Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_contacts_service.h

Issue 10818017: contacts: Add GDataContactsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_H_
7
8 #include <set>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/time.h"
17 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h"
18 #include "googleurl/src/gurl.h"
19
20 class Profile;
21
22 namespace base {
23 class Value;
24 }
25
26 namespace contacts {
27 struct Contact;
28 }
29
30 namespace gdata {
31
32 class GDataAuthService;
33 class GDataOperationRunner;
34
35 // Interface for fetching a user's Google contacts via the Contacts API
36 // (described at https://developers.google.com/google-apps/contacts/v3/).
37 class GDataContactsServiceInterface {
38 public:
39 typedef base::Callback<void(scoped_ptr<ScopedVector<contacts::Contact> >)>
40 SuccessCallback;
41 typedef base::Closure FailureCallback;
42
43 virtual ~GDataContactsServiceInterface() {}
44
45 virtual void Initialize() = 0;
46
47 // Downloads all contacts changed at or after |min_update_time| and invokes
48 // the appropriate callback asynchronously on the UI thread when complete. If
49 // min_update_time.is_null() is true, all contacts will be returned.
50 virtual void DownloadContacts(SuccessCallback success_callback,
51 FailureCallback failure_callback,
52 const base::Time& min_update_time) = 0;
53
54 protected:
55 GDataContactsServiceInterface() {}
56
57 private:
58 DISALLOW_COPY_AND_ASSIGN(GDataContactsServiceInterface);
59 };
60
61 class GDataContactsService : public GDataContactsServiceInterface {
62 public:
63 typedef base::Callback<std::string(const std::string&)>
64 RewritePhotoUrlCallback;
65
66 explicit GDataContactsService(Profile* profile);
67 virtual ~GDataContactsService();
68
69 GDataAuthService* auth_service_for_testing();
70
71 void set_max_simultaneous_photo_downloads_for_testing(int max_downloads) {
72 max_simultaneous_photo_downloads_ = max_downloads;
73 }
74 void set_feed_url_for_testing(const GURL& url) {
75 feed_url_for_testing_ = url;
76 }
77 void set_rewrite_photo_url_callback_for_testing(RewritePhotoUrlCallback cb) {
78 rewrite_photo_url_callback_for_testing_ = cb;
79 }
80
81 // Overridden from GDataContactsServiceInterface:
82 virtual void Initialize() OVERRIDE;
83 virtual void DownloadContacts(SuccessCallback success_callback,
84 FailureCallback failure_callback,
85 const base::Time& min_update_time) OVERRIDE;
86
87 private:
88 class DownloadContactsRequest;
89
90 // Invoked by a download request once it's finished (either successfully or
91 // unsuccessfully).
92 void OnRequestComplete(DownloadContactsRequest* request);
93
94 Profile* profile_; // not owned
95
96 scoped_ptr<GDataOperationRunner> runner_;
97
98 // In-progress download requests. Pointers are owned by this class.
99 std::set<DownloadContactsRequest*> requests_;
100
101 // If non-empty, URL that will be used to fetch the feed. URLs contained
102 // within the feed will also be modified to use the host and port from this
103 // member.
104 GURL feed_url_for_testing_;
105
106 // Maximum number of photos we'll try to download at once (per
107 // DownloadContacts() request).
108 int max_simultaneous_photo_downloads_;
109
110 // Callback that's invoked to rewrite photo URLs for tests. Called iff
111 // |feed_url_for_testing_| has been set.
112 RewritePhotoUrlCallback rewrite_photo_url_callback_for_testing_;
113
114 DISALLOW_COPY_AND_ASSIGN(GDataContactsService);
115 };
116
117 } // namespace gdata
118
119 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698