Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 GOOGLE_APIS_GCM_ENGINE_USER_LIST_H_ | |
| 6 #define GOOGLE_APIS_GCM_ENGINE_USER_LIST_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "google_apis/gcm/engine/gcm_store.h" | |
| 11 #include "google_apis/gcm/gcm_client.h" | |
| 12 | |
| 13 namespace gcm { | |
| 14 | |
| 15 class UserList { | |
|
Nicolas Zea
2014/01/13 19:26:06
Comment what the class is for
fgorski
2014/01/14 22:25:42
Done.
| |
| 16 public: | |
| 17 UserList(GCMStore* gcm_store); | |
|
Nicolas Zea
2014/01/13 19:26:06
nit: make this an explicit constructor
fgorski
2014/01/14 22:25:42
Done.
| |
| 18 virtual ~UserList(); | |
|
jianli
2014/01/13 19:19:55
Why virtual?
fgorski
2014/01/14 22:25:42
Done.
| |
| 19 | |
| 20 // A callback invoked once the Backend is done loading the mappings. | |
|
jianli
2014/01/13 19:19:55
The comment is very confusing.
fgorski
2014/01/14 22:25:42
Done.
| |
| 21 void Initialize(const GCMStore::LoadResult& result); | |
|
Nicolas Zea
2014/01/13 19:26:06
Seems a bit strange that this consumes a GCMStore
fgorski
2014/01/14 22:25:42
Done.
| |
| 22 | |
| 23 // Sets a user delegate for a |username|. It will create a new entry for the | |
|
Nicolas Zea
2014/01/13 19:26:06
nit: for a |username| -> for |username|. Also, sho
fgorski
2014/01/14 22:25:42
Done.
| |
| 24 // user if one does not exist. | |
| 25 void AddDelegate(const std::string& username, GCMClient::Delegate* delegate); | |
| 26 | |
| 27 // Adds a |serial_number| to the user entry identified by the |username|. | |
| 28 // It expects an entry to already exist and not have a serial_number set. | |
| 29 // |callback| will be run once an entry is successfully persisted. | |
| 30 void AddSerialNumber(const std::string& username, | |
|
Nicolas Zea
2014/01/13 19:26:06
Perhaps call this SetUserSerialNumber?
fgorski
2014/01/14 22:25:42
I encapsulated the serial number related actions a
| |
| 31 int64 serial_number, | |
| 32 const GCMStore::UpdateCallback& callback); | |
| 33 | |
| 34 // Returns a delegate for the user identified by |serial_number|. | |
| 35 GCMClient::Delegate* GetDelegateBySerialNumber(int64 serial_number) const; | |
|
Nicolas Zea
2014/01/13 19:26:06
nit: mention what happens if the serial number isn
fgorski
2014/01/14 22:25:42
Done.
| |
| 36 | |
| 37 // Returns a delegate for the user identified by |username|. | |
| 38 GCMClient::Delegate* GetDelegateByUsername(const std::string& username) const; | |
| 39 | |
| 40 // Returns a serial number of a user identified by |username|. | |
| 41 bool GetSerialNumberForUsername(const std::string& username, | |
| 42 int64* serial_number) const; | |
| 43 | |
| 44 // Returns a next available serial number. | |
| 45 int64 GetNextSerialNumber(); | |
|
Nicolas Zea
2014/01/13 19:26:06
It still seems weird to me that the serial number
fgorski
2014/01/14 22:25:42
Done. Moved to private and renamed to IncrementSer
| |
| 46 | |
| 47 private: | |
| 48 friend class UserListTest; | |
| 49 | |
| 50 struct UserDelegate { | |
| 51 UserDelegate(const std::string& username, GCMClient::Delegate* delegate); | |
| 52 UserDelegate(const std::string& username, int64 serial_number); | |
| 53 ~UserDelegate(); | |
| 54 | |
| 55 std::string username; | |
| 56 int64 serial_number; | |
| 57 // Delegate related to the username. Not owned by the UserDelegate. | |
| 58 GCMClient::Delegate* delegate; | |
| 59 }; | |
| 60 typedef std::vector<UserDelegate> DelegateList; | |
|
jianli
2014/01/13 19:19:55
nit: please include vector.
In addition, I think
fgorski
2014/01/14 22:25:42
Done.
| |
| 61 | |
| 62 // Returns a const iterator pointing to the entry identified by |username|. | |
| 63 DelegateList::const_iterator GetByUsername(const std::string& username) const; | |
| 64 | |
| 65 // Returns an iterator pointing to the entry identified by |username|. | |
| 66 DelegateList::iterator GetByUsernameForUpdate(const std::string& username); | |
| 67 | |
| 68 // A callback invoked once the Backend is done updating the next serial | |
| 69 // number. | |
| 70 void NextSerialNumberUpdateCompleted(bool success); | |
| 71 | |
| 72 // Sets the serial number related to the username. It expect the entry to not | |
|
Nicolas Zea
2014/01/13 19:26:06
nit: expect -> expects
fgorski
2014/01/14 22:25:42
Done.
| |
| 73 // exist yet and will create it. | |
| 74 void SetSerialNumber(const std::string& username, int64 serial_number); | |
| 75 | |
| 76 int64 next_serial_number_; | |
| 77 DelegateList delegates_; | |
| 78 GCMStore* gcm_store_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(UserList); | |
| 81 }; | |
| 82 | |
| 83 } // namespace gcm | |
| 84 | |
| 85 #endif // GOOGLE_APIS_GCM_ENGINE_USER_LIST_H_ | |
| OLD | NEW |