1 // Copyright (C) 2013 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // The interface to be implemented by the user of the library to enable 16 // downloading validation rules from a server. 17 18 #ifndef I18N_ADDRESSINPUT_DOWNLOADER_H_ 19 #define I18N_ADDRESSINPUT_DOWNLOADER_H_ 20 21 #include <libaddressinput/callback.h> 22 #include <libaddressinput/util/scoped_ptr.h> 23 24 #include <string> 25 26 namespace i18n { 27 namespace addressinput { 28 29 // Downloads validation rules from the server. Sample usage: 30 // class MyDownloader : public Downloader { 31 // public: 32 // virtual void Download(const std::string& url, 33 // scoped_ptr<Callback> downloaded) const { 34 // bool success = ... 35 // std::string data = ... 36 // (*downloaded)(success, url, data); 37 // } 38 // }; 39 class Downloader { 40 public: 41 typedef i18n::addressinput::ScopedPtrCallback<void(std::string, std::string)> 42 Callback; 43 ~Downloader()44 virtual ~Downloader() {} 45 46 // Downloads |url| and invokes the |downloaded| callback. 47 virtual void Download(const std::string& url, 48 scoped_ptr<Callback> downloaded) = 0; 49 }; 50 51 } // namespace addressinput 52 } // namespace i18n 53 54 #endif // I18N_ADDRESSINPUT_DOWNLOADER_H_ 55