OLD | NEW |
---|---|
(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 void Initialize() = 0; | |
44 | |
45 // Downloads all contacts changed at or after |min_update_time| and invokes | |
46 // the appropriate callback asynchronously on the UI thread when complete. If | |
47 // min_update_time.is_null() is true, all contacts will be returned. | |
satorux1
2012/07/24 18:25:51
I'm curious. Why is |min_update_time| parameter is
Daniel Erat
2012/07/24 20:37:21
This lets us do incremental updates. Jumping ahea
| |
48 virtual void DownloadContacts(SuccessCallback success_callback, | |
49 FailureCallback failure_callback, | |
50 const base::Time& min_update_time) = 0; | |
51 | |
52 protected: | |
53 GDataContactsServiceInterface() {} | |
54 virtual ~GDataContactsServiceInterface() {} | |
55 | |
56 private: | |
57 DISALLOW_COPY_AND_ASSIGN(GDataContactsServiceInterface); | |
58 }; | |
59 | |
60 class GDataContactsService : public GDataContactsServiceInterface { | |
61 public: | |
62 typedef base::Callback<std::string(const std::string&)> | |
63 RewritePhotoUrlCallback; | |
64 | |
65 explicit GDataContactsService(Profile* profile); | |
66 virtual ~GDataContactsService(); | |
67 | |
68 GDataAuthService* auth_service_for_testing(); | |
69 | |
70 void set_max_simultaneous_photo_downloads_for_testing(int max_downloads) { | |
71 max_simultaneous_photo_downloads_ = max_downloads; | |
72 } | |
73 void set_feed_url_for_testing(const GURL& url) { | |
74 feed_url_for_testing_ = url; | |
75 } | |
76 void set_rewrite_photo_url_callback_for_testing(RewritePhotoUrlCallback cb) { | |
77 rewrite_photo_url_callback_for_testing_ = cb; | |
78 } | |
79 | |
80 // Overridden from GDataContactsServiceInterface: | |
81 virtual void Initialize() OVERRIDE; | |
82 virtual void DownloadContacts(SuccessCallback success_callback, | |
83 FailureCallback failure_callback, | |
84 const base::Time& min_update_time) OVERRIDE; | |
85 | |
86 private: | |
87 class DownloadContactsRequest; | |
88 | |
89 // Invoked by a download request once it's finished (either successfully or | |
90 // unsuccessfully). | |
91 void OnRequestComplete(DownloadContactsRequest* request); | |
92 | |
93 Profile* profile_; // not owned | |
94 | |
95 scoped_ptr<GDataOperationRunner> runner_; | |
96 | |
97 // In-progress download requests. Pointers are owned by this class. | |
98 std::set<DownloadContactsRequest*> requests_; | |
99 | |
100 // If non-empty, URL that will be used to fetch the feed. URLs contained | |
101 // within the feed will also be modified to use the host and port from this | |
102 // member. | |
103 GURL feed_url_for_testing_; | |
104 | |
105 // Maximum number of photos we'll try to download at once (per | |
106 // DownloadContacts() request). | |
107 int max_simultaneous_photo_downloads_; | |
108 | |
109 // Callback that's invoked to rewrite photo URLs for tests. Called iff | |
110 // |feed_url_for_testing_| has been set. | |
111 RewritePhotoUrlCallback rewrite_photo_url_callback_for_testing_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(GDataContactsService); | |
114 }; | |
115 | |
116 } // namespace gdata | |
117 | |
118 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_H_ | |
OLD | NEW |