OLD | NEW |
---|---|
1 // Copyright (C) 2013 Google Inc. | 1 // Copyright (C) 2013 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include <string> | 25 #include <string> |
26 | 26 |
27 #include "lookup_key_util.h" | 27 #include "lookup_key_util.h" |
28 | 28 |
29 namespace i18n { | 29 namespace i18n { |
30 namespace addressinput { | 30 namespace addressinput { |
31 | 31 |
32 class Downloader; | 32 class Downloader; |
33 class Storage; | 33 class Storage; |
34 | 34 |
35 // Retrieves data. Sample usage: | 35 // Manages downloading data and caching it locally. Sample usage: |
36 // Storage* storage = ...; | 36 // Storage* storage = ...; |
37 // Downloader* downloader = ...; | 37 // Downloader* downloader = ...; |
38 // Retriever retriever("https://i18napis.appspot.com/ssl-address/", | 38 // Retriever retriever("https://i18napis.appspot.com/ssl-address/", |
39 // downloader, storage); | 39 // downloader, storage); |
40 // retriever.Retrieve("data/CA/AB--fr", | 40 // retriever.Retrieve("data/CA/AB--fr", |
41 // BuildCallback(this, &MyClass::OnDataRetrieved)); | 41 // BuildCallback(this, &MyClass::OnDataRetrieved)); |
42 class Retriever { | 42 class Retriever { |
43 public: | 43 public: |
44 typedef i18n::addressinput::Callback<std::string, std::string> Callback; | 44 typedef i18n::addressinput::Callback<std::string, std::string> Callback; |
45 | 45 |
46 Retriever(const std::string& validation_data_url, | 46 Retriever(const std::string& validation_data_url, |
47 scoped_ptr<Downloader> downloader, | 47 scoped_ptr<Downloader> downloader, |
48 scoped_ptr<Storage> storage); | 48 scoped_ptr<Storage> storage); |
49 ~Retriever(); | 49 ~Retriever(); |
50 | 50 |
51 // Retrieves the data for |key| and invokes the |retrieved| callback. Checks | 51 // Retrieves the data for |key| and invokes the |retrieved| callback. Checks |
52 // for the data in storage first. If storage does not have the data for |key|, | 52 // for the data in storage first. If storage does not have the data for |key|, |
53 // then downloads the data and places it in storage. | 53 // then downloads the data and places it in storage. |
54 void Retrieve(const std::string& key, scoped_ptr<Callback> retrieved); | 54 void Retrieve(const std::string& key, scoped_ptr<Callback> retrieved); |
55 | 55 |
56 private: | 56 private: |
57 // Callback for when a rule is retrieved from |storage_|. | 57 // Callback for when a rule is retrieved from |storage_|. |
58 void OnDataRetrievedFromStorage(bool success, | 58 void OnDataRetrievedFromStorage(bool success, |
59 const std::string& key, | 59 const std::string& key, |
60 const std::string& data); | 60 const std::string& downloaded_data); |
please use gerrit instead
2014/01/16 00:50:15
The .cc file renamed the variable for the OnDownlo
Evan Stade
2014/01/16 01:09:10
good catch, fixed.
| |
61 | 61 |
62 // Callback for when a rule is retrieved by |downloader_|. | 62 // Callback for when a rule is retrieved by |downloader_|. |
63 void OnDownloaded(bool success, | 63 void OnDownloaded(bool success, |
64 const std::string& url, | 64 const std::string& url, |
65 const std::string& data); | 65 const std::string& data); |
66 | 66 |
67 // Looks up the callback for |key| in |requests_|, removes it from the map | 67 // Looks up the callback for |key| in |requests_|, removes it from the map |
68 // and returns it. Assumes that |key| is in fact in |requests_|. | 68 // and returns it. Assumes that |key| is in fact in |requests_|. |
69 scoped_ptr<Callback> GetCallbackForKey(const std::string& key); | 69 scoped_ptr<Callback> GetCallbackForKey(const std::string& key); |
70 | 70 |
71 const LookupKeyUtil lookup_key_util_; | 71 const LookupKeyUtil lookup_key_util_; |
72 scoped_ptr<Downloader> downloader_; | 72 scoped_ptr<Downloader> downloader_; |
73 scoped_ptr<Storage> storage_; | 73 scoped_ptr<Storage> storage_; |
74 // Holds pending requests. The callback pointers are owned. | 74 // Holds pending requests. The callback pointers are owned. |
75 std::map<std::string, Callback*> requests_; | 75 std::map<std::string, Callback*> requests_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(Retriever); | 77 DISALLOW_COPY_AND_ASSIGN(Retriever); |
78 }; | 78 }; |
79 | 79 |
80 } // namespace addressinput | 80 } // namespace addressinput |
81 } // namespace i18n | 81 } // namespace i18n |
82 | 82 |
83 #endif // I18N_ADDRESSINPUT_RETRIEVER_H_ | 83 #endif // I18N_ADDRESSINPUT_RETRIEVER_H_ |
OLD | NEW |